Author vstinner
Recipients germn, pitrou, r.david.murray, vstinner, yselivanov
Date 2017-09-21.16:07:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1506010078.86.0.256301726826.issue31539@psf.upfronthosting.co.za>
In-reply-to
Content
Clocks is a very complex topic, especially when you care of portability. See my PEP 418.

asyncio uses time.monotonic() clock to not be impacted when the system clock ("wall clock") is updated by the administrator or automatically by NTP.

On Windows, time.monotonic() is implemented with GetTickCount64() which has a bad resolution: around 15 ms. The exact resolution depends on the hardware.

See my PEP 418 which added time.monotonic() for Python 3.3 for much more information:
https://www.python.org/dev/peps/pep-0418/#monotonic-clocks

To get the clock resolution, use:

>>> import time; print(time.get_clock_info('monotonic'))

Example on Linux:

>>> import time; print(time.get_clock_info('monotonic'))
namespace(adjustable=False, implementation='clock_gettime(CLOCK_MONOTONIC)', monotonic=True, resolution=1e-09)

Well, the announced resolution is 1 nanosecond, but in practice it's more around 500 ns. At least, it's better than 15 ms :-)

--

asyncio rounds timings using the clock resolution, time.get_clock_info('monotonic').resolution. Search for self._clock_resolution in Lib/asyncio/base_events.py.

asyncio is not designed for real time.
History
Date User Action Args
2017-09-21 16:07:58vstinnersetrecipients: + vstinner, pitrou, r.david.murray, yselivanov, germn
2017-09-21 16:07:58vstinnersetmessageid: <1506010078.86.0.256301726826.issue31539@psf.upfronthosting.co.za>
2017-09-21 16:07:58vstinnerlinkissue31539 messages
2017-09-21 16:07:58vstinnercreate