Retrieve wall-time in Python using the standard library?
Asked Answered
I

1

7

How can I retrieve wall-time in Python using the standard library?

This question, and this question would suggest that something like clock_gettime(CLOCK_MONOTONIC_RAW) or /proc/uptime are most appropriate on Linux. On Windows, time.clock() has the desired effect.

I would use time.time(), but the function is not guaranteed to return monotonically (and linearly) increasing time values.

Inotropic answered 14/1, 2011 at 2:22 Comment(0)
C
6

Victor Stinner wrote a Python implementation of a monotonic timer. See http://bugs.python.org/issue10278 for the discussion and the docs for the upcoming 3.3 release referencing the new feature (coded in C).

There is also Monoclock:

Monoclock is a Python module that provides access to the monotonic clock on POSIX-like OSes that have librt.

Compatibility: tested on CPython 2.6.5, CPython 2.7, pypy 1.3, and pypy 1.4.

Crossroad answered 14/1, 2011 at 2:33 Comment(1)
Great work. It looks like clock_gettime and friends will be exposed in 3.3, as well as monotonic clocks used where appropriate for internal Python time-related stuff.Inotropic

© 2022 - 2024 — McMap. All rights reserved.