Skip to content

Commit 846a152

Browse files
committed
loop.time: Don't use libuv's time cache (issue #29)
1 parent f853407 commit 846a152

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

tests/test_base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ def cb():
5959

6060
self.assertFalse(self.loop.is_closed())
6161

62+
def test_now_update(self):
63+
async def run():
64+
st = self.loop.time()
65+
time.sleep(0.05)
66+
return self.loop.time() - st
67+
68+
delta = self.loop.run_until_complete(run())
69+
self.assertTrue(delta > 0.049 and delta < 0.6)
70+
6271
def test_call_later(self):
6372
calls = []
6473

uvloop/includes/uv.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ cdef extern from "uv.h" nogil:
264264
int uv_loop_close(uv_loop_t* loop)
265265
int uv_loop_alive(uv_loop_t* loop)
266266

267+
void uv_update_time(uv_loop_t* loop)
267268
uint64_t uv_now(const uv_loop_t*)
268269

269270
int uv_run(uv_loop_t*, uv_run_mode mode) nogil

uvloop/loop.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ cdef class Loop:
395395
executor.shutdown(wait=False)
396396

397397
cdef uint64_t _time(self):
398+
# asyncio doesn't have a time cache, neither should uvloop.
399+
uv.uv_update_time(self.uvloop) # void
398400
return uv.uv_now(self.uvloop)
399401

400402
cdef inline _queue_write(self, UVStream stream):

0 commit comments

Comments
 (0)