This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients anacrolix, belopolsky, brian.curtin, eric.araujo, glenn, kristjan.jonsson, michael.foord, pitrou, python-dev, vstinner
Date 2011-10-25.11:28:21
SpamBayes Score 1.3746781e-12
Marked as misclassified No
Message-id <1319542102.4.0.630134203876.issue10278@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2011-10-25 11:28:22vstinnersetrecipients: + vstinner, belopolsky, pitrou, kristjan.jonsson, eric.araujo, michael.foord, brian.curtin, glenn, anacrolix, python-dev
2011-10-25 11:28:22vstinnersetmessageid: <1319542102.4.0.630134203876.issue10278@psf.upfronthosting.co.za>
2011-10-25 11:28:21vstinnerlinkissue10278 messages
2011-10-25 11:28:21vstinnercreate