Skip to content

Commit

Permalink
[3.12] pythongh-123978: Remove broken time.thread_time() on NetBSD (p…
Browse files Browse the repository at this point in the history
…ythonGH-124116)

(cherry picked from commit e670a11)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
  • Loading branch information
serhiy-storchaka committed Sep 24, 2024
1 parent 0e838b5 commit b736ab6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove broken :func:`time.thread_time` and :func:`time.thread_time_ns` on NetBSD.
19 changes: 16 additions & 3 deletions Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1292,8 +1292,14 @@ _PyTime_GetProcessTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
#else

/* 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(CLOCK_PROCESS_CPUTIME_ID) || defined(CLOCK_PROF)) \
&& !defined(__NetBSD__)
struct timespec ts;

if (HAVE_CLOCK_GETTIME_RUNTIME) {
Expand Down Expand Up @@ -1499,9 +1505,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__) && defined(__has_attribute) && __has_attribute(availability)
Expand Down

0 comments on commit b736ab6

Please sign in to comment.