From e2403bde0a29b58d2107eb03edd241dc609b7397 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 20 Apr 2014 05:58:12 +0300 Subject: [PATCH] asyncio: Make run_forever() actually run forever. --- asyncio/asyncio.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/asyncio/asyncio.py b/asyncio/asyncio.py index 5713459e..e5c174a5 100644 --- a/asyncio/asyncio.py +++ b/asyncio/asyncio.py @@ -39,13 +39,17 @@ class EventLoop: time.sleep(delay) def run_forever(self): - while self.q: -# t, cnt, cb, args = self.q.pop(0) - t, cnt, cb, args = heapq.heappop(self.q) - tnow = self.time() - delay = t - tnow - if delay > 0: - self.wait(delay) + while True: + if self.q: + t, cnt, cb, args = heapq.heappop(self.q) + tnow = self.time() + delay = t - tnow + if delay > 0: + self.wait(delay) + else: + self.wait(-1) + # Assuming IO completion scheduled some tasks + continue if callable(cb): cb(*args) else: