Title: Monotonic time on macOS 10.12+ should use mach_continuous_time()
Type: behavior Stage:
Components: macOS Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ned.deily, ronaldoussoren, sjunot, vstinner
Priority: normal Keywords:

Created on 2020-10-21 10:37 by sjunot, last changed 2020-10-21 18:55 by ronaldoussoren.

Messages (2)
msg379204 - (view) Author: Seth Junot (sjunot) Date: 2020-10-21 10:37
This blog post describes an issue with Apple's "CLOCK_UPTIME_RAW" where the clock is reset after a system that hibernates:

According to Apple's documentation, CLOCK_UPTIME_RAW corresponds to mach_absolute_time():

CPython is using mach_absolute_time() for its time.monotonic() implementation:

time.monotonic() ought to be backed by the more appropriate mach_continuous_time() ("CLOCK_MONOTONIC_RAW"). Note it was introduced in macOS 10.12+:
msg379231 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2020-10-21 18:55
See also #41303, which discusses using mach_continuous_time in another context.

If using a different clock is necessary I'd prefer to use clock_gettime(CLOCK_MONOTONIC_RAW) instead of mach_continuous_time(), as the former is a more cross-platform API.

BTW. Please hold off from merging a patch for this until the macOS 11 support code in #41100 is in, this is bound to cause a merge conflict otherwise.
Date User Action Args
2020-10-21 18:55:54ronaldoussorensetmessages: + msg379231
2020-10-21 17:52:59ned.deilysetnosy: + vstinner
2020-10-21 10:37:25sjunotcreate