Skip to content

Commit 784da49

Browse files
committed
Round delay in call_later()
* Fixes MagicStack#233.
1 parent 7a4f00a commit 784da49

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

tests/test_base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,19 @@ def cb(arg):
171171
self.loop.run_forever()
172172
self.assertEqual(calls, ['a'])
173173

174+
def test_call_later_rounding(self):
175+
# Refs #233, call_later() and call_at() shouldn't call cb early
176+
177+
def cb():
178+
self.loop.stop()
179+
180+
for i in range(16):
181+
self.loop.call_later(0.000928039662539959, cb)
182+
started = time.monotonic()
183+
self.loop.run_forever()
184+
finished = time.monotonic()
185+
self.assertGreater(finished - started, 0.001)
186+
174187
def test_call_at(self):
175188
if os.environ.get('TRAVIS_OS_NAME'):
176189
# Time seems to be really unpredictable on Travis.

uvloop/loop.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ cdef class Loop:
12541254
# infinity for a Python application.
12551255
delay = 3600 * 24 * 365 * 100
12561256

1257-
when = <uint64_t>(delay * 1000)
1257+
when = <uint64_t>round(delay * 1000)
12581258
if not args:
12591259
args = None
12601260
if when == 0:

0 commit comments

Comments
 (0)