uvloop icon indicating copy to clipboard operation
uvloop copied to clipboard

Uvloop internal clock is not microsecond accurate

Open agronholm opened this issue 3 years ago • 5 comments

  • 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.

agronholm avatar Aug 27 '20 22:08 agronholm

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()

agronholm avatar Aug 27 '20 22:08 agronholm

That's correct, libuv only has a millisecond accuracy for its timers.

jlaine avatar Aug 28 '20 09:08 jlaine

Oh dear, so it's not fixable I guess?

agronholm avatar Aug 28 '20 09:08 agronholm

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.

1st1 avatar Aug 28 '20 23:08 1st1

FWIW, here's an old libuv PR that is related: https://github.com/libuv/libuv/pull/1191

elprans avatar Aug 28 '20 23:08 elprans