File tree 1 file changed +11
-7
lines changed
1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 13
13
14
14
NUMTASKS = 10
15
15
NUMTRIPS = 3
16
- POLL_SLEEP = 0.010 # seconds = 10 ms
17
16
18
17
_print_mutex = thread .allocate_lock ()
19
18
@@ -121,19 +120,24 @@ def task():
121
120
122
121
with threading_helper .wait_threads_exit ():
123
122
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
126
126
self .assertEqual (thread ._count (), orig + 1 )
127
+
127
128
# Allow the task to finish.
128
129
mut .release ()
130
+
129
131
# 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.
132
134
done = []
133
135
wr = weakref .ref (task , lambda _ : done .append (None ))
134
136
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
137
141
support .gc_collect () # For PyPy or other GCs.
138
142
self .assertEqual (thread ._count (), orig )
139
143
You can’t perform that action at this time.
0 commit comments