@@ -1288,9 +1288,14 @@ py_process_time(time_module_state *state, PyTime_t *tp,
12881288
12891289 /* clock_gettime */
12901290// gh-115714: Don't use CLOCK_PROCESS_CPUTIME_ID on WASI.
1291+ /* CLOCK_PROF is defined on NetBSD, but not supported.
1292+ * CLOCK_PROCESS_CPUTIME_ID is broken on NetBSD for the same reason as
1293+ * CLOCK_THREAD_CPUTIME_ID (see comment below).
1294+ */
12911295#if defined(HAVE_CLOCK_GETTIME ) \
12921296 && (defined(CLOCK_PROCESS_CPUTIME_ID ) || defined(CLOCK_PROF )) \
1293- && !defined(__wasi__ )
1297+ && !defined(__wasi__ ) \
1298+ && !defined(__NetBSD__ )
12941299 struct timespec ts ;
12951300
12961301 if (HAVE_CLOCK_GETTIME_RUNTIME ) {
@@ -1483,9 +1488,16 @@ _PyTime_GetThreadTimeWithInfo(PyTime_t *tp, _Py_clock_info_t *info)
14831488 return 0 ;
14841489}
14851490
1491+ /* CLOCK_THREAD_CPUTIME_ID is broken on NetBSD: the result of clock_gettime()
1492+ * includes the sleeping time, that defeats the purpose of the clock.
1493+ * Also, clock_getres() does not support it.
1494+ * https://github.com/python/cpython/issues/123978
1495+ * https://gnats.netbsd.org/57512
1496+ */
14861497#elif defined(HAVE_CLOCK_GETTIME ) && \
1487- defined(CLOCK_PROCESS_CPUTIME_ID ) && \
1488- !defined(__EMSCRIPTEN__ ) && !defined(__wasi__ )
1498+ defined(CLOCK_THREAD_CPUTIME_ID ) && \
1499+ !defined(__EMSCRIPTEN__ ) && !defined(__wasi__ ) && \
1500+ !defined(__NetBSD__ )
14891501#define HAVE_THREAD_TIME
14901502
14911503#if defined(__APPLE__ ) && _Py__has_attribute (availability )
0 commit comments