diff options
author | Petr Viktorin <encukou@gmail.com> | 2024-02-22 11:39:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-22 11:39:45 (GMT) |
commit | 8aa372edcd857d2fbec8da0cb993de15b4179308 (patch) | |
tree | 9a4b0d5f217df44e7558dc660877aa7bf4f5020d | |
parent | baae73d7307214ee97abbe80aaa8c1c773a6f682 (diff) | |
download | cpython-8aa372edcd857d2fbec8da0cb993de15b4179308.zip cpython-8aa372edcd857d2fbec8da0cb993de15b4179308.tar.gz cpython-8aa372edcd857d2fbec8da0cb993de15b4179308.tar.bz2 |
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
-rw-r--r-- | Misc/NEWS.d/next/Library/2024-02-22-12-10-18.gh-issue-115714.P2JsU1.rst | 4 | ||||
-rw-r--r-- | Modules/timemodule.c | 16 |
2 files changed, 15 insertions, 5 deletions
diff --git a/Misc/NEWS.d/next/Library/2024-02-22-12-10-18.gh-issue-115714.P2JsU1.rst b/Misc/NEWS.d/next/Library/2024-02-22-12-10-18.gh-issue-115714.P2JsU1.rst new file mode 100644 index 0000000..fb62634 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-02-22-12-10-18.gh-issue-115714.P2JsU1.rst @@ -0,0 +1,4 @@ +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()``. diff --git a/Modules/timemodule.c b/Modules/timemodule.c index fc493bde..ed41ffd 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -76,7 +76,8 @@ static int pysleep(PyTime_t timeout); 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 @@ -1210,7 +1211,8 @@ PyDoc_STRVAR(perf_counter_ns_doc, 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) @@ -1278,8 +1280,10 @@ py_process_time(time_module_state *state, PyTime_t *tp, #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) { @@ -1341,7 +1345,8 @@ py_process_time(time_module_state *state, PyTime_t *tp, #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; @@ -2068,7 +2073,8 @@ time_exec(PyObject *module) } #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, |