@@ -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