@@ -76,7 +76,8 @@ static int pysleep(PyTime_t timeout);
76
76
77
77
typedef struct {
78
78
PyTypeObject * struct_time_type ;
79
- #ifdef HAVE_TIMES
79
+ // gh-115714: Don't use times() on WASI.
80
+ #if defined(HAVE_TIMES ) && !defined(__wasi__ )
80
81
// times() clock frequency in hertz
81
82
_PyTimeFraction times_base ;
82
83
#endif
@@ -1210,7 +1211,8 @@ PyDoc_STRVAR(perf_counter_ns_doc,
1210
1211
Performance counter for benchmarking as nanoseconds." );
1211
1212
1212
1213
1213
- #ifdef HAVE_TIMES
1214
+ // gh-115714: Don't use times() on WASI.
1215
+ #if defined(HAVE_TIMES ) && !defined(__wasi__ )
1214
1216
static int
1215
1217
process_time_times (time_module_state * state , PyTime_t * tp ,
1216
1218
_Py_clock_info_t * info )
@@ -1278,8 +1280,10 @@ py_process_time(time_module_state *state, PyTime_t *tp,
1278
1280
#else
1279
1281
1280
1282
/* clock_gettime */
1283
+ // gh-115714: Don't use CLOCK_PROCESS_CPUTIME_ID on WASI.
1281
1284
#if defined(HAVE_CLOCK_GETTIME ) \
1282
- && (defined(CLOCK_PROCESS_CPUTIME_ID ) || defined(CLOCK_PROF ))
1285
+ && (defined(CLOCK_PROCESS_CPUTIME_ID ) || defined(CLOCK_PROF )) \
1286
+ && !defined(__wasi__ )
1283
1287
struct timespec ts ;
1284
1288
1285
1289
if (HAVE_CLOCK_GETTIME_RUNTIME ) {
@@ -1341,7 +1345,8 @@ py_process_time(time_module_state *state, PyTime_t *tp,
1341
1345
#endif
1342
1346
1343
1347
/* times() */
1344
- #ifdef HAVE_TIMES
1348
+ // gh-115714: Don't use times() on WASI.
1349
+ #if defined(HAVE_TIMES ) && !defined(__wasi__ )
1345
1350
int res = process_time_times (state , tp , info );
1346
1351
if (res < 0 ) {
1347
1352
return -1 ;
@@ -2068,7 +2073,8 @@ time_exec(PyObject *module)
2068
2073
}
2069
2074
#endif
2070
2075
2071
- #ifdef HAVE_TIMES
2076
+ // gh-115714: Don't use times() on WASI.
2077
+ #if defined(HAVE_TIMES ) && !defined(__wasi__ )
2072
2078
long ticks_per_second ;
2073
2079
if (_Py_GetTicksPerSecond (& ticks_per_second ) < 0 ) {
2074
2080
PyErr_SetString (PyExc_RuntimeError ,
0 commit comments