From eef054d98a6bc1e54d6b1b81f8ddb3dc448f7341 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 20 Aug 2017 17:04:31 +0300 Subject: [PATCH] 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. --- uasyncio.core/uasyncio/core.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/uasyncio.core/uasyncio/core.py b/uasyncio.core/uasyncio/core.py index 319e74d6..fcb7bd2b 100644 --- a/uasyncio.core/uasyncio/core.py +++ b/uasyncio.core/uasyncio/core.py @@ -59,9 +59,12 @@ class EventLoop: t = self.q.peektime() tnow = self.time() delay = time.ticks_diff(t, tnow) - if delay <= 0: - break + if delay < 0: + delay = 0 + # Always call wait(), to give a chance to I/O scheduling self.wait(delay) + if delay == 0: + break self.q.pop(cur_task) t = cur_task[0]