New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement time.monotonic() on Mac OS X #58312
Comments
time.monotonic() can use mach_absolute_time() on Mac OS X. mach_timebase_info() may be used to convert the result to a number of seconds. Examples: https://github.com/ThomasHabets/monotonic_clock/blob/master/src/monotonic_mach.c Another way is to use clock_get_time() with host_get_clock_service(SYSTEM_CLOCK). Example: https://github.com/gavinbeatty/python-monotonic-time/blob/master/darwin.c |
Attached is a patch which implements time.monotonic() using mach_absolute_time() / mach_timebase_info(). This was recommended by Apple in their technical Q&A 1398: |
Is it possible that mach_timebase_info() fails? No according to the Technical Q&A QA1398.
"time * timebase.numer" may overflow, you should maybe multiply using the double type to avoid the overflow. |
timebase.numer and timebase.denom are always 1 in practice (see the "note" in the tech Q&A); I included them for completeness, but maybe it's just better to not bother? |
In this case, you will not lose precision and it's safe to cast to double to multiply and divide ;-) |
OK, you have a point :-) New patch attached. |
New changeset 3c875719e46d by Victor Stinner in branch 'default': |
Path commited, thanks for the patch Nicholas! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: