[Python-Dev] cpython: Issue #10278: Add an optional strict argument to time.steady(), False by default (original) (raw)

Victor Stinner victor.stinner at gmail.com
Mon Mar 19 13:35:49 CET 2012


This is not clear to me.  Why wouldn't it raise OSError on error even with strict=False?  Please clarify which exception is raised in which case.

It seems clear to me. It doesn't raise exceptions when strict=False because it falls back to a non-monotonic clock. If strict is True and a non-monotonic clock is not available it raises OSError or NotImplementedError. So errors are ignored when strict is false?

Said differently: time.steady(strict=True) is always monotonic (*), whereas time.steady() may or may not be monotonic, depending on what is avaiable.

time.steady() is a best-effort steady clock.

(*) time.steady(strict=True) relies on the OS monotonic clock. If the OS provides a "not really monotonic" clock, Python cannot do better. For example, clock_gettime(CLOCK_MONOTONIC) speed can be adjusted by NTP on Linux. Python tries to use clock_gettime(CLOCK_MONOTONIC_RAW) which doesn't have this issue.

Victor



More information about the Python-Dev mailing list