File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 1313
1414NUMTASKS = 10
1515NUMTRIPS = 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
You can’t perform that action at this time.
0 commit comments