Skip to content

Commit eef054d

Browse files
committed
uasyncio.core: Make I/O scheduling fair wrt to computational scheduling.
If there is a coroutine to run immediately (with wait delay <= 0), uasyncio.core never called .wait() method, which is required to process I/O events (and schedule coroutines waiting for them). So now, call .wait(0) even if there's a coroutine to run immediately.
1 parent 65605e3 commit eef054d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

uasyncio.core/uasyncio/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ def run_forever(self):
5959
t = self.q.peektime()
6060
tnow = self.time()
6161
delay = time.ticks_diff(t, tnow)
62-
if delay <= 0:
63-
break
62+
if delay < 0:
63+
delay = 0
64+
# Always call wait(), to give a chance to I/O scheduling
6465
self.wait(delay)
66+
if delay == 0:
67+
break
6568

6669
self.q.pop(cur_task)
6770
t = cur_task[0]

0 commit comments

Comments
 (0)