Skip to content

Commit bddbd80

Browse files
authored
test_thread uses support.sleeping_retry() (#93849)
test_thread.test_count() now fails if it takes longer than LONG_TIMEOUT seconds.
1 parent d318346 commit bddbd80

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Lib/test/test_thread.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
NUMTASKS = 10
1515
NUMTRIPS = 3
16-
POLL_SLEEP = 0.010 # seconds = 10 ms
1716

1817
_print_mutex = thread.allocate_lock()
1918

@@ -121,19 +120,24 @@ def task():
121120

122121
with threading_helper.wait_threads_exit():
123122
thread.start_new_thread(task, ())
124-
while not started:
125-
time.sleep(POLL_SLEEP)
123+
for _ in support.sleeping_retry(support.LONG_TIMEOUT):
124+
if started:
125+
break
126126
self.assertEqual(thread._count(), orig + 1)
127+
127128
# Allow the task to finish.
128129
mut.release()
130+
129131
# The only reliable way to be sure that the thread ended from the
130-
# interpreter's point of view is to wait for the function object to be
131-
# destroyed.
132+
# interpreter's point of view is to wait for the function object to
133+
# be destroyed.
132134
done = []
133135
wr = weakref.ref(task, lambda _: done.append(None))
134136
del task
135-
while not done:
136-
time.sleep(POLL_SLEEP)
137+
138+
for _ in support.sleeping_retry(support.LONG_TIMEOUT):
139+
if done:
140+
break
137141
support.gc_collect() # For PyPy or other GCs.
138142
self.assertEqual(thread._count(), orig)
139143

0 commit comments

Comments
 (0)