uvloop
uvloop copied to clipboard
Uvloop internal clock is not microsecond accurate
- uvloop version: 0.14, master
- Python version: 3.6
- Platform: Linux
-
Can you reproduce the bug with
PYTHONASYNCIODEBUG
in env?: yes - Does uvloop behave differently from vanilla asyncio? How?: loop.time() reports time with the accuracy of milliseconds on uvloop, microseconds (or greater) on the stdlib event loop.
Today I debugged some failing tests in the httpcore project and it turns out they were relying on time passing between two subsequent operations. The code was running so fast, however, that the returned clock value on uvloop was the same as it was before, due to the lesser accuracy. This should hopefully be easy to fix.
Easy repro:
from asyncio.events import get_event_loop
import uvloop
loop = get_event_loop()
print('stdlib:', loop.time())
loop.close()
uvloop.install()
loop = get_event_loop()
print('uvloop:', loop.time())
loop.close()
That's correct, libuv only has a millisecond accuracy for its timers.
Oh dear, so it's not fixable I guess?
Fixable by submitting a PR to libuv to allow higher resolution timers on platforms that support that. That's very doable (maybe you can work on a PR?) just might take a bit longer.
FWIW, here's an old libuv PR that is related: https://github.com/libuv/libuv/pull/1191