time.monotonic() roll over

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Dec 5 05:09:07 EST 2014


Lele Gaifax wrote:

> Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:
> 
>> The most conservative approach is to assume that while you're suspended,
>> *everything else* is suspended too, so when you resume you still have to
>> sleep for the full N seconds.
> 
> That's an intriguing interpretation of what sleep() should do, but I
> fail to see *how* the function could even attempt to do that: should it
> keep its own notion of the elapsed time?

Provided that the operating system can provide a monotonic clock that only
ticks while the process calling it is running, that shouldn't be hard. The
only tricky part is if the monotonic clock rolls over.

I'm not sure how the OS would implement that, but most OSes supply a global
monotonic clock, so it's probably possible. I leave that as an exercise to
the reader :-)

Here's a discussion from the Factor programming language:

http://code-factor.blogspot.com.au/2009/11/monotonic-timers.html



-- 
Steven




More information about the Python-list mailing list