8000 gh-115714: Don't use CLOCK_PROCESS_CPUTIME_ID and times() on WASI (GH… · python/cpython@8aa372e · GitHub
[go: up one dir, main page]

Skip to content

Commit 8aa372e

Browse files
authored
gh-115714: Don't use CLOCK_PROCESS_CPUTIME_ID and times() on WASI (GH-115757)
* gh-115714: Don't use CLOCK_PROCESS_CPUTIME_ID and times() on WASI * Add blurb
1 parent baae73d commit 8aa372e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
On WASI, the :mod:`time` module no longer get process time using ``times()``
2+
or ``CLOCK_PROCESS_CPUTIME_ID``, system API is that is unreliable and is
3+
likely to be removed from WASI. The affected clock functions fall back to
4+
calling ``clock()``.

Modules/timemodule.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ static int pysleep(PyTime_t timeout);
7676

7777
typedef struct {
7878
PyTypeObject *struct_time_type;
79-
#ifdef HAVE_TIMES
79+
// gh-115714: Don't use times() on WASI.
80+
#if defined(HAVE_TIMES) && !defined(__wasi__)
8081
// times() clock frequency in hertz
8182
_PyTimeFraction times_base;
8283
#endif
@@ -1210,7 +1211,8 @@ PyDoc_STRVAR(perf_counter_ns_doc,
12101211
Performance counter for benchmarking as nanoseconds.");
12111212

12121213

1213-
#ifdef HAVE_TIMES
1214+
// gh-115714: Don't use times() on WASI.
1215+
#if defined(HAVE_TIMES) && !defined(__wasi__)
12141216
static int
12151217
process_time_times(time_module_state *state, PyTime_t *tp,
12161218
_Py_clock_info_t *info)
@@ -1278,8 +1280,10 @@ py_process_time(time_module_state *state, PyTime_t *tp,
12781280
#else
12791281

12801282
/* clock_gettime */
1283+
// gh-115714: Don't use CLOCK_PROCESS_CPUTIME_ID on WASI.
12811284
#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__)
12831287
struct timespec ts;
12841288

12851289
if (HAVE_CLOCK_GETTIME_RUNTIME) {
@@ -1341,7 +1345,8 @@ py_process_time(time_module_state *state, PyTime_t *tp,
13411345
#endif
13421346

13431347
/* times() */
1344-
#ifdef HAVE_TIMES
1348+
// gh-115714: Don't use times() on WASI.
1349+
#if defined(HAVE_TIMES) && !defined(__wasi__)
13451350
int res = process_time_times(state, tp, info);
13461351
if (res < 0) {
13471352
return -1;
@@ -2068,7 +2073,8 @@ time_exec(PyObject *module)
20682073
}
20692074
#endif
20702075

2071-
#ifdef HAVE_TIMES
2076+
// gh-115714: Don't use times() on WASI.
2077+
#if defined(HAVE_TIMES) && !defined(__wasi__)
20722078
long ticks_per_second;
20732079
if (_Py_GetTicksPerSecond(&ticks_per_second) < 0) {
20742080
PyErr_SetString(PyExc_RuntimeError,

0 commit comments

Comments
 (0)
0