[Python-Dev] Drop the new time.wallclock() function? (original) (raw)
Victor Stinner victor.stinner at gmail.com
Wed Mar 14 01:29:46 CET 2012
- Previous message: [Python-Dev] Drop the new time.wallclock() function?
- Next message: [Python-Dev] Drop the new time.wallclock() function?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 14/03/2012 01:18, Nadeem Vawda wrote:
So wallclock() falls back to a not-necessarily-monotonic time source if necessary, while monotonic() raises an exception in that case? ISTM that these don't need to be separate functions - rather, we can have one function that takes a flag (called requiremonotonic, or something like that) telling it which failure mode to use. Does that make sense?
I don't think that time.monotonic() can fail in practice and it is available for all modern platforms (Windows, Mac OS X and OS implemented clock_gettime()).
On Windows, time.monotonic() fails with an OSError if QueryPerformanceFrequency() failed. QueryPerformanceFrequency() can fail if "the installed hardware does not support a high-resolution performance counter" according to Microsoft documentation. Windows uses the CPU RDTSC instruction, or the ACPI power management timer or event the old 8245 PIT. I think that you have at least one of this device on your computer.
I suppose that you can use a manual fallback to time.time() if time.monotonic() failed. If time.monotonic() fails, it fails directly at the first call. Example of a fallback working with Python < 3.3:
try: time.monotonic() except (OSError, AttributeError): get_time = time.time else: get_time = time.monotonic
Victor
- Previous message: [Python-Dev] Drop the new time.wallclock() function?
- Next message: [Python-Dev] Drop the new time.wallclock() function?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]