[Python-Dev] Questions for the PEP 418: monotonic vs steady, is_adjusted
victor.stinner at gmail.com
Sat Apr 14 02:51:09 CEST 2012
Before posting a first draft of the PEP 418 to python-dev, I have some
== Naming: time.monotonic() or time.steady()? ==
I like the "steady" name but different people complained that the
steady name should not be used if the function falls back to the
system clock or if the clock is adjusted.
time.monotonic() does not fallback to the system clock anymore, it is
now always monotonic.
There is only one clock used by time.monotonic() which is adjusted:
CLOCK_MONOTONIC on Linux. On Linux, CLOCK_MONOTONIC is slewed by NTP,
but not stepped. From the user point of view, the clock *is* steady.
IMO CLOCK_MONOTONIC_RAW is less steady than CLOCK_MONOTONIC.
CLOCK_MONOTONIC_RAW does drift from the real time, whereas NTP adjusts
CLOCK_MONOTONIC to make it following closer to the real time. (I mean
"real time" as defined in the Glossary of the PEP, not "civil time.)
I prefer "steady" over "monotonic" because the steady property is what
users really expect from a "monotonic" clock. A monotonic but not
steady clock may be useless.
All clocks used by the time.monotonic() of the PEP *are* steady.
time.monotonic() should be the most steady clock of all available
clocks. It may not have the best precision, use time.perf_counter() is
you need the highest available precision, but you don't care if the
clock is steady or not.
== "is_adjusted" key of time.get_clock_info() ==
time.get_clock_info() returns a dict with an optional key:
"is_adjusted". This flag indicates "if the clock *can be* adjusted".
Should it be called "is_adjustable" instead? On Windows, the flag
value may change at runtime when NTP is enabled or disabled. So the
value is the current status of the clock adjustement. The description
may be changed to "if the clock *is* adjusted".
Is a single flag enough? Or would be it better to indicate if the
clock: only slewed, slewed *and* stepped, or not adjusted? (3 possible
values) I guess that a single flag is enough. If you need more precise
information, use the "implementation" information.
More information about the Python-Dev