[Python-Dev] PEP 418: Add monotonic clock

Nick Coghlan ncoghlan at gmail.com
Wed Mar 28 06:45:33 CEST 2012


On Wed, Mar 28, 2012 at 10:36 AM, Victor Stinner
<victor.stinner at gmail.com> wrote:
> If QueryPerformanceCounter() is monotonic, the API can be simplified to:
>
>  * time.time() = system clock
>  * time.monotonic() = monotonic clock
>  * time.hires() = monotonic clock or fallback to system clock
>
> time.hires() definition is exactly what I was trying to implement with
> "time.steady(strict=True)" / "time.try_monotonic()".

Please don't call the fallback version "hires" as it suggests it may
be higher resolution than time.time() and that's completely the wrong
idea. If we're simplifying the idea to only promising a monotonic
clock (i.e. will never go backwards within a given process, but may
produce the same value for an indefinite period, and may jump forwards
by arbitrarily large amounts), then we're back to being able to
enforce monotonicity even if the underlying clock jumps backwards due
to system clock adjustments.

Specifically:

time.time() = system clock
time._monotonic() = system level monotonic clock (if it exists)

time.monotonic() = clock based on either time._monotonic() (if
available) or time.time() (if not) that enforces monotonicity of
returned values.

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list