You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
assignee=Noneclosed_at=<Date2012-03-12.23:27:28.933>created_at=<Date2012-02-23.23:09:14.831>labels= ['library']
title='Implement time.monotonic() on Mac OS X'updated_at=<Date2012-03-12.23:29:14.621>user='https://github.com/vstinner'
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:
Attached is a patch which implements time.monotonic() using
mach_absolute_time() / mach_timebase_info().
Is it possible that mach_timebase_info() fails? No according to the Technical Q&A QA1398.
time * timebase.numer / timebase.denom
"time * timebase.numer" may overflow, you should maybe multiply using the double type to avoid the overflow.
nicholasriley commented on Mar 12, 2012
nicholasrileymannequin
Mannequin
More actions
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?
Activity
vstinner commentedon Feb 23, 2012
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
http://svn.boost.org/svn/boost/trunk/boost/chrono/detail/inlined/mac/chrono.hpp
(search steady_clock)
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
nicholasriley commentedon Mar 12, 2012
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:
https://developer.apple.com/library/mac/#qa/qa1398/
vstinner commentedon Mar 12, 2012
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.
nicholasriley commentedon Mar 12, 2012
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?
vstinner commentedon Mar 12, 2012
In this case, you will not lose precision and it's safe to cast to double to multiply and divide ;-)
nicholasriley commentedon Mar 12, 2012
OK, you have a point :-) New patch attached.
python-dev commentedon Mar 12, 2012
New changeset 3c875719e46d by Victor Stinner in branch 'default':
Issue bpo-14104: Implement time.monotonic() on Mac OS X,
http://hg.python.org/cpython/rev/3c875719e46d
vstinner commentedon Mar 12, 2012
Path commited, thanks for the patch Nicholas!