[WIP] bpo-36205: incorrect time.process_time when built on macOS < 10.12 by ned-deily · Pull Request #12287 · python/cpython
bpo-36205 documents a problem where time.process_time and time.perf_counter return very different values when built on macOS 10.11 or earlier. Several time related functions were added to macOS at 10.12 including clock_gettime. For older systems, timemodule.c falls back to using getrusage. With Python 3.6.x, that fallbacks correctly but it appears that refactoring introduced with the implementation of PEP 564 (bpo-31784, #3989) broke that for 3.7.z.
This initial PR just includes a potential test case to ensure process_time and perf_counter return similar results. It can be used to reproduce the problem when building on newer versions of macOS (10.12+) by removing the AC_CHECK_FUNCS(clock_gettime) test in configure.ac:
diff --git a/configure.ac b/configure.ac
index 73ee71c6d2..0c61a088d9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3853,15 +3853,6 @@ char *r = crypt_r("", "", &d);
[])
)
-AC_CHECK_FUNCS(clock_gettime, [], [
- AC_CHECK_LIB(rt, clock_gettime, [
- LIBS="$LIBS -lrt"
- AC_DEFINE(HAVE_CLOCK_GETTIME, 1)
- AC_DEFINE(TIMEMODULE_LIB, [rt],
- [Library needed by timemodule.c: librt may be needed for clock_gettime()])
- ])
-])
-
AC_CHECK_FUNCS(clock_getres, [], [
AC_CHECK_LIB(rt, clock_getres, [
AC_DEFINE(HAVE_CLOCK_GETRES, 1)
autoconf && ./configure -q && make -s && \
./python.exe -m test test_time -m test_perf_counter_vs_process_time