From 9796f03a82a0b340a7381a3008e16d656df2fed2 Mon Sep 17 00:00:00 2001 From: Ewald de Wit Date: Mon, 21 Sep 2020 18:54:47 +0200 Subject: [PATCH] Prevent infinite loop when asyncio.sleep(0) is used in a loop (fixes #34) --- nest_asyncio.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nest_asyncio.py b/nest_asyncio.py index 7b7466a..5f17c0b 100644 --- a/nest_asyncio.py +++ b/nest_asyncio.py @@ -117,7 +117,9 @@ def _run_once(self): handle = heappop(scheduled) ready.append(handle) - while ready: + for _ in range(len(ready)): + if not ready: + break handle = ready.popleft() if not handle._cancelled: handle._run()