[Python-Dev] PEP 418: Add monotonic clock

Guido van Rossum guido at python.org
Fri Mar 30 21:40:25 CEST 2012


On Fri, Mar 30, 2012 at 12:01 PM, Lennart Regebro <regebro at gmail.com> wrote:
> The overview of the different monotonic clocks was interesting,
> because only one of them is adjusted by NTP, and that's the unix
> CLOCK_MONOTONIC. Hence we don't need a raw=False flag, which I
> previously suggested, we only need to not use CLOCK_MONOTONIC (which
> the PEP psuedo-code indeed also does not do, so that's all good).

Right on.

> That means I think the PEP is fine now, if we rename highres().
> time.time() already gets the highest resolution clock it can.

No, time.time() is the clock that can be mapped to and from "civil
time". (Adjustments by NTP and the user notwithstanding.) The other
clocks have a variable epoch and do not necessarily tick with a
constant rate (e.g. they may not tick at all while the system is
suspended).

> Hence a
> highres() is confusing as the name implies that it returns a higher
> resolution clock than time.time(). And the name does not in any way
> indicate that the returned clock might be monotonic. try_monotonic()
> seems the obvious choice, since that's what it actually does.

I am still unhappy with the two names, but I'm glad that we're this
close. We need two new names; one for an OS-provided clock that is
"monotonic" or "steady" or whatever you want to call it, but which may
not exist on all systems (some platforms don't have it, some host may
not have it even though the platform generally does have it). The
other name is for a clock that's one or the other; it should be the
OS-provided clock if it exists, otherwise time.time(). Most code
should probably use this one, so perhaps its name should be the
shorter one.

C++ calls these steady_clock and high_resolution_clock, respectively.
But it also calls the civil time clock system_clock, so perhaps we
shouldn't feel to bound by it (except that we *shouldn't* call
something steady if it isn't).

I still think the name "monotonic" give the wrong impression; I would
be happy calling it steady.

But for the other, I'm still at a loss, and that name is the most
important one. We can't call it steady because it isn't always.
highres or hires sounds awkward; try_monotonic or try_steady are even
more awkward. I looked in an online thesaurus and here's a list of
what it gave:

Big Ben, alarm, chroniker, chronograph, chronometer, digital watch,
hourglass, metronome, pendulum, stopwatch, sundial, tattler,
tick-tock, ticker, timekeeper, timemarker, timepiece, timer, turnip,
watch

I wonder if something with tick would work? (Even though it returns a float. :-)

If all else fails, I'd go with turnip.

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list