--- /dev/null
+On WASI, the :mod:`time` module no longer get process time using ``times()``
+or ``CLOCK_PROCESS_CPUTIME_ID``, system API is that is unreliable and is
+likely to be removed from WASI. The affected clock functions fall back to
+calling ``clock()``.
typedef struct {
PyTypeObject *struct_time_type;
-#ifdef HAVE_TIMES
+// gh-115714: Don't use times() on WASI.
+#if defined(HAVE_TIMES) && !defined(__wasi__)
// times() clock frequency in hertz
_PyTimeFraction times_base;
#endif
Performance counter for benchmarking as nanoseconds.");
-#ifdef HAVE_TIMES
+// gh-115714: Don't use times() on WASI.
+#if defined(HAVE_TIMES) && !defined(__wasi__)
static int
process_time_times(time_module_state *state, PyTime_t *tp,
_Py_clock_info_t *info)
#else
/* clock_gettime */
+// gh-115714: Don't use CLOCK_PROCESS_CPUTIME_ID on WASI.
#if defined(HAVE_CLOCK_GETTIME) \
- && (defined(CLOCK_PROCESS_CPUTIME_ID) || defined(CLOCK_PROF))
+ && (defined(CLOCK_PROCESS_CPUTIME_ID) || defined(CLOCK_PROF)) \
+ && !defined(__wasi__)
struct timespec ts;
if (HAVE_CLOCK_GETTIME_RUNTIME) {
#endif
/* times() */
-#ifdef HAVE_TIMES
+// gh-115714: Don't use times() on WASI.
+#if defined(HAVE_TIMES) && !defined(__wasi__)
int res = process_time_times(state, tp, info);
if (res < 0) {
return -1;
}
#endif
-#ifdef HAVE_TIMES
+// gh-115714: Don't use times() on WASI.
+#if defined(HAVE_TIMES) && !defined(__wasi__)
long ticks_per_second;
if (_Py_GetTicksPerSecond(&ticks_per_second) < 0) {
PyErr_SetString(PyExc_RuntimeError,