]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-123978: Remove broken time.thread_time() on NetBSD (GH-124116)
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 24 Sep 2024 08:26:25 +0000 (11:26 +0300)
committerGitHub <noreply@github.com>
Tue, 24 Sep 2024 08:26:25 +0000 (08:26 +0000)
Misc/NEWS.d/next/Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst [new file with mode: 0644]
Modules/timemodule.c

diff --git a/Misc/NEWS.d/next/Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst b/Misc/NEWS.d/next/Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst
new file mode 100644 (file)
index 0000000..e5b3229
--- /dev/null
@@ -0,0 +1 @@
+Remove broken :func:`time.thread_time` and :func:`time.thread_time_ns` on NetBSD.
index 46f85bc9c30f9c399545d79dc7b12f66dde46c8d..ee59fb73ac1e319ffbe72f252a04d027436fa41f 100644 (file)
@@ -1288,9 +1288,14 @@ py_process_time(time_module_state *state, PyTime_t *tp,
 
     /* clock_gettime */
 // gh-115714: Don't use CLOCK_PROCESS_CPUTIME_ID on WASI.
+/* CLOCK_PROF is defined on NetBSD, but not supported.
+ * CLOCK_PROCESS_CPUTIME_ID is broken on NetBSD for the same reason as
+ * CLOCK_THREAD_CPUTIME_ID (see comment below).
+ */
 #if defined(HAVE_CLOCK_GETTIME) \
     && (defined(CLOCK_PROCESS_CPUTIME_ID) || defined(CLOCK_PROF)) \
-    && !defined(__wasi__)
+    && !defined(__wasi__) \
+    && !defined(__NetBSD__)
     struct timespec ts;
 
     if (HAVE_CLOCK_GETTIME_RUNTIME) {
@@ -1483,9 +1488,16 @@ _PyTime_GetThreadTimeWithInfo(PyTime_t *tp, _Py_clock_info_t *info)
     return 0;
 }
 
+/* CLOCK_THREAD_CPUTIME_ID is broken on NetBSD: the result of clock_gettime()
+ * includes the sleeping time, that defeats the purpose of the clock.
+ * Also, clock_getres() does not support it.
+ * https://github.com/python/cpython/issues/123978
+ * https://gnats.netbsd.org/57512
+ */
 #elif defined(HAVE_CLOCK_GETTIME) && \
-      defined(CLOCK_PROCESS_CPUTIME_ID) && \
-      !defined(__EMSCRIPTEN__) && !defined(__wasi__)
+      defined(CLOCK_THREAD_CPUTIME_ID) && \
+      !defined(__EMSCRIPTEN__) && !defined(__wasi__) && \
+      !defined(__NetBSD__)
 #define HAVE_THREAD_TIME
 
 #if defined(__APPLE__) && _Py__has_attribute(availability)