This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Monotonic time on macOS 10.12+ should use mach_continuous_time()
Type: behavior Stage:
Components: macOS Versions: Python 3.10
process
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 2022-04-11 14:59 by admin.

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:

https://rachelbythebay.com/w/2020/10/20/ticktock/

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

https://developer.apple.com/documentation/kernel/1462446-mach_absolute_time

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

https://github.com/python/cpython/blob/f660567/Python/pytime.c#L7

time.monotonic() ought to be backed by the more appropriate mach_continuous_time() ("CLOCK_MONOTONIC_RAW"). Note it was introduced in macOS 10.12+:

https://developer.apple.com/documentation/kernel/1646199-mach_continuous_time
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.
History
Date User Action Args
2022-04-11 14:59:37adminsetgithub: 86273
2020-10-21 18:55:54ronaldoussorensetmessages: + msg379231
2020-10-21 17:52:59ned.deilysetnosy: + vstinner
2020-10-21 10:37:25sjunotcreate