Message146357
I closed maybe this issue too quickly. My commit doesn't solve the initial issue: Python doesn't provide a portable "wallclock" function.
wallclock.patch should be updated to use:
- time.clock() on Windows (use QueryPerformanceCounter)
- or time.clock_gettime(CLOCK_MONOTONIC_RAW) if available
- or time.clock_gettime(CLOCK_MONOTONIC) if available
- or time.time() (which is usually gettimeofday())
Pseudo-code:
wallclock = None
if hasattr(time, 'clock_gettime') and hasattr(time, 'CLOCK_MONOTONIC_RAW'):
# I understood that CLOCK_MONOTONIC_RAW is more reliable
# than CLOCK_MONOTONIC, because CLOCK_MONOTONIC may be adjusted
# by NTP. I don't know if it's correct.
def wallclock():
return time.clock_gettime(CLOCK_MONOTONIC_RAW)
elif hasattr(time, 'clock_gettime') and hasattr(time, 'CLOCK_MONOTONIC'):
def wallclock():
return time.clock_gettime(CLOCK_MONOTONIC)
elif os.name == 'nt':
# define a new function to be able to set its docstring
def wallclock():
return time.clock()
else:
def wallclock():
return time.time()
if wallclock is not None:
wallclock.__doc__ = 'monotonic time'
else:
del wallclock
wallclock() doc should also explain that time.time() may be adjusted by NTP or manually by the administrator.
--
By the way, it would be nice to expose the precision of time.clock(): it's 1/divisor or 1/CLOCKS_PER_SEC on Windows, 1/CLOCKS_PER_SEC on UNIX. |
|
Date |
User |
Action |
Args |
2011-10-25 11:28:22 | vstinner | set | recipients:
+ vstinner, belopolsky, pitrou, kristjan.jonsson, eric.araujo, michael.foord, brian.curtin, glenn, anacrolix, python-dev |
2011-10-25 11:28:22 | vstinner | set | messageid: <1319542102.4.0.630134203876.issue10278@psf.upfronthosting.co.za> |
2011-10-25 11:28:21 | vstinner | link | issue10278 messages |
2011-10-25 11:28:21 | vstinner | create | |
|