[Python-Dev] Use QueryPerformanceCounter() for time.monotonic() and/or time.highres()? (original) (raw)
Guido van Rossum guido at python.org
Sun Apr 1 05:46:04 CEST 2012
- Previous message: [Python-Dev] Use QueryPerformanceCounter() for time.monotonic() and/or time.highres()?
- Next message: [Python-Dev] [Python-checkins] cpython: Issue #14435: Add Misc/NEWS and Misc/ACKS
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, Mar 31, 2012 at 7:37 PM, Victor Stinner <victor.stinner at gmail.com> wrote:
If we provide a way to check if the monotonic clock is monotonic (or not), I agree to drop the flag from time.monotonic(fallback=True) and always fallback. I was never a fan of the "truly monotonic clock".
time.clockinfo('monotonic')['ismonotonic'] is a good candidate to store this information. I updated the PEP to add time.getclockinfo() and to drop the fallback parameter of time.monotonic() (which now always falls back). Because "monotonic" word cannot define time.monotonic() anymore, I suggest to rename the time.monotonic() function to time.steady(). So we would have: - time.steady() may or may not be monotonic, but its is as steady as possible. - time.getclockinfo('steady')['ismonotonic'] which looks less surprising than time.getclockinfo('monotonic')['ismonotonic'] It doesn't follow the C++ steadyclock definition, but it looks like the Boost library doesn't follow the C++ definition... (it uses CLOCKMONOTONIC on Linux) By the way, it now prefer to use CLOCKMONOTONIC instead of CLOCKMONOTONICRAW on Linux. It is what I need in practice. If the hardware clock is a little bit too fast or too slow, NTP adjusts its rate so a delta of two timestamps is really a number of seconds. It's not yet written explicitly in the PEP, but the unit of time.monotonic/time.steady and time.highres is a second.
Hmm... I believe NTP can also slew the clock to deal with leap seconds (which the POSIX standard requires must be ignored). That is, when a leap second is inserted, the clock is supposed to stop value for one second. What actually happens is that for some time around the leap second (I've heard maybe a day), the clock is slowed down slightly. I'm guessing that this affects CLOCK_MONOTONIC but not CLOCK_MONOTONIC_RAW. Personally I'd rather use the latter -- if I want to be synchronous with wall clock time, I can just use time.time().
-- --Guido van Rossum (python.org/~guido)
- Previous message: [Python-Dev] Use QueryPerformanceCounter() for time.monotonic() and/or time.highres()?
- Next message: [Python-Dev] [Python-checkins] cpython: Issue #14435: Add Misc/NEWS and Misc/ACKS
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]