summaryrefslogtreecommitdiffstats
path: root/Lib/test/support/threading_helper.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-06-15 12:09:56 (GMT)
committerGitHub <noreply@github.com>2022-06-15 12:09:56 (GMT)
commit0ba80273f2dba5b70de870a333e65ad025cca640 (patch)
tree7f21af5a00c17463625072031650af5bd50895ea /Lib/test/support/threading_helper.py
parentbddbd80cff950b16712ae9e72eeba2a0f26c65e0 (diff)
downloadcpython-0ba80273f2dba5b70de870a333e65ad025cca640.zip
cpython-0ba80273f2dba5b70de870a333e65ad025cca640.tar.gz
cpython-0ba80273f2dba5b70de870a333e65ad025cca640.tar.bz2
Use support.sleeping_retry() and support.busy_retry() (#93848)
* Replace time.sleep(0.010) with sleeping_retry() to use an exponential sleep. * support.wait_process(): reuse sleeping_retry(). * _test_eintr: remove unused variables.
Diffstat (limited to 'Lib/test/support/threading_helper.py')
-rw-r--r--Lib/test/support/threading_helper.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/Lib/test/support/threading_helper.py b/Lib/test/support/threading_helper.py
index 26cbc6f..b9973c8 100644
--- a/Lib/test/support/threading_helper.py
+++ b/Lib/test/support/threading_helper.py
@@ -88,19 +88,17 @@ def wait_threads_exit(timeout=None):
yield
finally:
start_time = time.monotonic()
- deadline = start_time + timeout
- while True:
+ for _ in support.sleeping_retry(timeout, error=False):
+ support.gc_collect()
count = _thread._count()
if count <= old_count:
break
- if time.monotonic() > deadline:
- dt = time.monotonic() - start_time
- msg = (f"wait_threads() failed to cleanup {count - old_count} "
- f"threads after {dt:.1f} seconds "
- f"(count: {count}, old count: {old_count})")
- raise AssertionError(msg)
- time.sleep(0.010)
- support.gc_collect()
+ else:
+ dt = time.monotonic() - start_time
+ msg = (f"wait_threads() failed to cleanup {count - old_count} "
+ f"threads after {dt:.1f} seconds "
+ f"(count: {count}, old count: {old_count})")
+ raise AssertionError(msg)
def join_thread(thread, timeout=None):