[Python-Dev] this is why we shouldn't call it a "monotonic clock" (was: PEP 418 is too divisive and confusing and should be postponed)

Victor Stinner victor.stinner at gmail.com
Wed Apr 11 01:06:27 CEST 2012


>> We're going around in circles. I'm not asking what sleep does, I want
>> on principle a timer that does the same thing as sleep(), regardless
>> of how sleep() works. So if on some OS sleep() uses the same algorithm
>> as CLOCK_MONOTONIC_RAW, I want my timer to use that too. But if on
>> some other OS sleep() uses CLOCK_MONOTONIC, I want my timer there to
>> use that. And if on some OS sleep() is buggy and uses the time-of-day
>> clock, well, I wouldn't mind if my timer used the same thing.
>
> sleep() takes a number of seconds as argument, so CLOCK_MONOTONIC
> should be used, not CLOCK_MONOTONIC_RAW. If I understood correctly,
> the unit of CLOCK_MONOTONIC is a second, whereas CLOCK_MONOTONIC_RAW
> may be faster or slower than a second.

sleep() is not affected by system clock update on any OS: I tested
Linux, FreeBSD, Mac OS X and OpenIndiana.

By the way, CLOCK_BOOTTIME was added to Linux 2.6.39: it includes time
elapsed during system suspend, whereas CLOCK_MONOTONIC doesn't include
time elapsed during system suspend. I updated the "Monotonic clocks"
table to indicate if the clock includes the elapsed time or not.
http://www.python.org/dev/peps/pep-0418/#monotonic-clocks

Victor


More information about the Python-Dev mailing list