diff options
| author | Victor Stinner <vstinner@python.org> | 2022-06-15 11:52:13 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-15 11:52:13 (GMT) |
| commit | bddbd80cff950b16712ae9e72eeba2a0f26c65e0 (patch) | |
| tree | 360ff06275222e2408c16e9131a715a0745fa4d4 /Lib/test/test_thread.py | |
| parent | d31834688bccb41fc136f780db83ffa12bef8cbd (diff) | |
| download | cpython-bddbd80cff950b16712ae9e72eeba2a0f26c65e0.zip cpython-bddbd80cff950b16712ae9e72eeba2a0f26c65e0.tar.gz cpython-bddbd80cff950b16712ae9e72eeba2a0f26c65e0.tar.bz2 | |
test_thread uses support.sleeping_retry() (#93849)
test_thread.test_count() now fails if it takes longer than
LONG_TIMEOUT seconds.
Diffstat (limited to 'Lib/test/test_thread.py')
| -rw-r--r-- | Lib/test/test_thread.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py index ed527e7..2ae5e9c 100644 --- a/Lib/test/test_thread.py +++ b/Lib/test/test_thread.py @@ -13,7 +13,6 @@ threading_helper.requires_working_threading(module=True) NUMTASKS = 10 NUMTRIPS = 3 -POLL_SLEEP = 0.010 # seconds = 10 ms _print_mutex = thread.allocate_lock() @@ -121,19 +120,24 @@ class ThreadRunningTests(BasicThreadTest): with threading_helper.wait_threads_exit(): thread.start_new_thread(task, ()) - while not started: - time.sleep(POLL_SLEEP) + for _ in support.sleeping_retry(support.LONG_TIMEOUT): + if started: + break self.assertEqual(thread._count(), orig + 1) + # Allow the task to finish. mut.release() + # The only reliable way to be sure that the thread ended from the - # interpreter's point of view is to wait for the function object to be - # destroyed. + # interpreter's point of view is to wait for the function object to + # be destroyed. done = [] wr = weakref.ref(task, lambda _: done.append(None)) del task - while not done: - time.sleep(POLL_SLEEP) + + for _ in support.sleeping_retry(support.LONG_TIMEOUT): + if done: + break support.gc_collect() # For PyPy or other GCs. self.assertEqual(thread._count(), orig) |
