Skip to content

Commit 77d7998

Browse files
[3.13] gh-123978: Remove broken time.thread_time() on NetBSD (GH-124116) (GH-124425)
(cherry picked from commit e670a11) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent bcc7227 commit 77d7998

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove broken :func:`time.thread_time` and :func:`time.thread_time_ns` on NetBSD.

Modules/timemodule.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,9 +1330,14 @@ py_process_time(time_module_state *state, PyTime_t *tp,
13301330

13311331
/* clock_gettime */
13321332
// gh-115714: Don't use CLOCK_PROCESS_CPUTIME_ID on WASI.
1333+
/* CLOCK_PROF is defined on NetBSD, but not supported.
1334+
* CLOCK_PROCESS_CPUTIME_ID is broken on NetBSD for the same reason as
1335+
* CLOCK_THREAD_CPUTIME_ID (see comment below).
1336+
*/
13331337
#if defined(HAVE_CLOCK_GETTIME) \
13341338
&& (defined(CLOCK_PROCESS_CPUTIME_ID) || defined(CLOCK_PROF)) \
1335-
&& !defined(__wasi__)
1339+
&& !defined(__wasi__) \
1340+
&& !defined(__NetBSD__)
13361341
struct timespec ts;
13371342

13381343
if (HAVE_CLOCK_GETTIME_RUNTIME) {
@@ -1525,9 +1530,16 @@ _PyTime_GetThreadTimeWithInfo(PyTime_t *tp, _Py_clock_info_t *info)
15251530
return 0;
15261531
}
15271532

1533+
/* CLOCK_THREAD_CPUTIME_ID is broken on NetBSD: the result of clock_gettime()
1534+
* includes the sleeping time, that defeats the purpose of the clock.
1535+
* Also, clock_getres() does not support it.
1536+
* https://github.com/python/cpython/issues/123978
1537+
* https://gnats.netbsd.org/57512
1538+
*/
15281539
#elif defined(HAVE_CLOCK_GETTIME) && \
1529-
defined(CLOCK_PROCESS_CPUTIME_ID) && \
1530-
!defined(__EMSCRIPTEN__) && !defined(__wasi__)
1540+
defined(CLOCK_THREAD_CPUTIME_ID) && \
1541+
!defined(__EMSCRIPTEN__) && !defined(__wasi__) && \
1542+
!defined(__NetBSD__)
15311543
#define HAVE_THREAD_TIME
15321544

15331545
#if defined(__APPLE__) && defined(__has_attribute) && __has_attribute(availability)

0 commit comments

Comments
 (0)