[Python-Dev] Drop the new time.wallclock() function?

Victor Stinner victor.stinner at gmail.com
Wed Mar 14 02:03:42 CET 2012


> I agree that it's better to have only one of these. I also think if we
> offer it we should always have it -- if none of the implementations
> are available, I guess you could fall back on returning time.time(),
> with some suitable offset so people don't think it is always the same.
> Maybe it could be called realtime()?

For a concrete use case, see for example:
http://bugs.python.org/issue14222

I just wrote two patches, for the queue and threading modules, using
time.monotonic() if available, with a fallback to time.time(). My
patches call time.monotonic() to ensure that it doesn't fail with
OSError.

I suppose that most libraries and programs will have to implement a
similar fallback.

We may merge both functions with a flag to be able to disable the
fallback. Example:

 - time.realtime(): best-effort monotonic, with a fallback
 - time.realtime(monotonic=True): monotonic, may raise OSError or
NotImplementedError

Victor


More information about the Python-Dev mailing list