@@ -1292,8 +1292,14 @@ _PyTime_GetProcessTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
1292
1292
#else
1293
1293
1294
1294
/* clock_gettime */
1295
+ // gh-115714: Don't use CLOCK_PROCESS_CPUTIME_ID on WASI.
1296
+ /* CLOCK_PROF is defined on NetBSD, but not supported.
1297
+ * CLOCK_PROCESS_CPUTIME_ID is broken on NetBSD for the same reason as
1298
+ * CLOCK_THREAD_CPUTIME_ID (see comment below).
1299
+ */
1295
1300
#if defined(HAVE_CLOCK_GETTIME ) \
1296
- && (defined(CLOCK_PROCESS_CPUTIME_ID ) || defined(CLOCK_PROF ))
1301
+ && (defined(CLOCK_PROCESS_CPUTIME_ID ) || defined(CLOCK_PROF )) \
1302
+ && !defined(__NetBSD__ )
1297
1303
struct timespec ts ;
1298
1304
1299
1305
if (HAVE_CLOCK_GETTIME_RUNTIME ) {
@@ -1499,9 +1505,16 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
1499
1505
return 0 ;
1500
1506
}
1501
1507
1508
+ /* CLOCK_THREAD_CPUTIME_ID is broken on NetBSD: the result of clock_gettime()
1509
+ * includes the sleeping time, that defeats the purpose of the clock.
1510
+ * Also, clock_getres() does not support it.
1511
+ * https://github.com/python/cpython/issues/123978
1512
+ * https://gnats.netbsd.org/57512
1513
+ */
1502
1514
#elif defined(HAVE_CLOCK_GETTIME ) && \
1503
- defined(CLOCK_PROCESS_CPUTIME_ID ) && \
1504
- !defined(__EMSCRIPTEN__ ) && !defined(__wasi__ )
1515
+ defined(CLOCK_THREAD_CPUTIME_ID ) && \
1516
+ !defined(__EMSCRIPTEN__ ) && !defined(__wasi__ ) && \
1517
+ !defined(__NetBSD__ )
1505
1518
#define HAVE_THREAD_TIME
1506
1519
1507
1520
#if defined(__APPLE__ ) && defined(__has_attribute ) && __has_attribute (availability )
0 commit comments