Skip to content

Commit f5ca51b

Browse files
committed
Fix call_later to update libuv time
1 parent 784f570 commit f5ca51b

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ clean:
1515
check-env:
1616
python -c "import cython; (cython.__version__ < '0.24') and exit(1)"
1717

18+
1819
clean-libuv:
1920
git -C vendor/libuv clean -dfX
2021

tests/test_base.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async def run():
111111
delta = self.loop.run_until_complete(run())
112112
self.assertTrue(delta > 0.049 and delta < 0.6)
113113

114-
def test_call_later(self):
114+
def test_call_later_1(self):
115115
calls = []
116116

117117
def cb(inc=10, stop=False):
@@ -142,6 +142,20 @@ def cb(inc=10, stop=False):
142142

143143
self.assertFalse(self.loop.is_running())
144144

145+
def test_call_later_2(self):
146+
# Test that loop.call_later triggers an update of
147+
# libuv cached time.
148+
149+
async def main():
150+
await asyncio.sleep(0.001)
151+
time.sleep(0.01)
152+
await asyncio.sleep(0.01)
153+
154+
started = time.monotonic()
155+
self.loop.run_until_complete(main())
156+
delta = time.monotonic() - started
157+
self.assertGreater(delta, 0.019)
158+
145159
def test_call_later_negative(self):
146160
calls = []
147161

uvloop/handles/timer.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ cdef class UVTimer(UVHandle):
4545
self._ensure_alive()
4646

4747
if self.running == 0:
48+
# Update libuv internal time.
49+
uv.uv_update_time(self._loop.uvloop) # void
50+
4851
err = uv.uv_timer_start(<uv.uv_timer_t*>self._handle,
4952
__uvtimer_callback,
5053
self.timeout, 0)

0 commit comments

Comments
 (0)