Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve wall-time in Python using the standard library?

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.

like image 515
Matt Joiner Avatar asked Jan 14 '11 02:01

Matt Joiner


People also ask

How to get the time in Python?

Time module in Python provides various time-related functions. This module comes under Python’s standard utility modules. time.time () method of Time module is used to get the time in seconds since epoch. The handling of leap seconds is platform dependent. Note: The epoch is the point where the time starts, and is platform dependent.

What is the Python time module?

The Python time module provides various time-related functions, such as getting the current time and suspending the calling thread’s execution for the given number of seconds. The below steps show how to use the time module to calculate the program’s execution time.

What is a standard library in Python?

The Python Standard Library ¶. The library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible to Python programmers, as well as modules written in Python that provide standardized solutions for many problems that occur in everyday programming.

What are the features of the Python library?

Python’s standard library is very extensive, offering a wide range of facilities as indicated by the long table of contents listed below. The library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible to Python programmers,...


1 Answers

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.

like image 147
TryPyPy Avatar answered Oct 07 '22 21:10

TryPyPy