homepage

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: Implement time.monotonic() on Mac OS X
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ned.deily, nicholas.riley, pitrou, python-dev, ronaldoussoren, vstinner
Priority: normal Keywords: patch

Created on 2012年02月23日 23:09 by vstinner, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
monotonic.patch nicholas.riley, 2012年03月12日 21:03 review
monotonic-2.patch nicholas.riley, 2012年03月12日 23:18 review
Messages (8)
msg154095 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012年02月23日 23:09
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 
msg155478 - (view) Author: Nicholas Riley (nicholas.riley) * Date: 2012年03月12日 21:03
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/ 
msg155502 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012年03月12日 22:42
> 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.
msg155507 - (view) Author: Nicholas Riley (nicholas.riley) * Date: 2012年03月12日 22:54
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?
msg155511 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012年03月12日 22:58
> timebase.numer and timebase.denom are always 1 in practice
In this case, you will not lose precision and it's safe to cast to double to multiply and divide ;-)
msg155515 - (view) Author: Nicholas Riley (nicholas.riley) * Date: 2012年03月12日 23:18
OK, you have a point :-) New patch attached.
msg155520 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012年03月12日 23:27
New changeset 3c875719e46d by Victor Stinner in branch 'default':
Issue #14104: Implement time.monotonic() on Mac OS X,
http://hg.python.org/cpython/rev/3c875719e46d 
msg155521 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012年03月12日 23:29
Path commited, thanks for the patch Nicholas!
History
Date User Action Args
2022年04月11日 14:57:27adminsetgithub: 58312
2012年03月12日 23:29:14vstinnersetmessages: + msg155521
2012年03月12日 23:27:28vstinnersetstatus: open -> closed
resolution: fixed
2012年03月12日 23:27:09python-devsetnosy: + python-dev
messages: + msg155520
2012年03月12日 23:18:03nicholas.rileysetfiles: + monotonic-2.patch

messages: + msg155515
2012年03月12日 23:02:00ned.deilysetstage: patch review
2012年03月12日 22:58:37vstinnersetmessages: + msg155511
2012年03月12日 22:54:32nicholas.rileysetmessages: + msg155507
2012年03月12日 22:42:51vstinnersetmessages: + msg155502
2012年03月12日 21:03:54nicholas.rileysetfiles: + monotonic.patch

nosy: + nicholas.riley
messages: + msg155478

keywords: + patch
2012年02月23日 23:31:26pitrousetnosy: + ronaldoussoren, ned.deily
2012年02月23日 23:09:14vstinnercreate

AltStyle によって変換されたページ (->オリジナル) /