[Python-checkins] test_asyncio: run_until() implements exponential sleep (#93866)

vstinner webhook-mailer at python.org
Wed Jun 15 12:28:09 EDT 2022


https://github.com/python/cpython/commit/41fccd23e9b4397d6cc294b42e1a198cd8f8b268
commit: 41fccd23e9b4397d6cc294b42e1a198cd8f8b268
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-06-15T18:28:00+02:00
summary:

test_asyncio: run_until() implements exponential sleep (#93866)

run_until() of test.test_asyncio.utils now uses an exponential sleep
delay (max: 1 second), rather than a fixed delay of 1 ms. Similar
design than support.sleeping_retry() wait strategy that applies
exponential backoff.

files:
M Lib/test/test_asyncio/utils.py

diff --git a/Lib/test/test_asyncio/utils.py b/Lib/test/test_asyncio/utils.py
index 07ef33d3fc244..507daa11c28bc 100644
--- a/Lib/test/test_asyncio/utils.py
+++ b/Lib/test/test_asyncio/utils.py
@@ -109,10 +109,12 @@ async def once():
 
 
 def run_until(loop, pred, timeout=support.SHORT_TIMEOUT):
+    delay = 0.001
     for _ in support.busy_retry(timeout, error=False):
         if pred():
             break
-        loop.run_until_complete(tasks.sleep(0.001))
+        loop.run_until_complete(tasks.sleep(delay))
+        delay = max(delay * 2, 1.0)
     else:
         raise futures.TimeoutError()
 



More information about the Python-checkins mailing list