6
6
import functools
7
7
import warnings
8
8
9
+ import time
9
10
from time import monotonic as _time
10
11
from _weakrefset import WeakSet
11
12
from itertools import count as _count
@@ -1112,6 +1113,7 @@ def _stop(self):
1112
1113
# module's _shutdown() function.
1113
1114
lock = self ._tstate_lock
1114
1115
if lock is not None :
1116
+ self ._log ("Checking _tstate_lock is unlocked" )
1115
1117
assert not lock .locked ()
1116
1118
self ._is_stopped = True
1117
1119
self ._tstate_lock = None
@@ -1182,6 +1184,11 @@ def _join_os_thread(self):
1182
1184
self ._handle = None
1183
1185
# No need to keep this around
1184
1186
self ._join_lock = None
1187
+ def _log (self , msg ):
1188
+ cur_thr_name = current_thread ()._name
1189
+ if cur_thr_name not in ("join-race-B" , "join-race-C" ):
1190
+ return
1191
+ print (f"[{ current_thread ()._name } join { self ._name } ] - { msg } " )
1185
1192
1186
1193
def _wait_for_tstate_lock (self , block = True , timeout = - 1 ):
1187
1194
# Issue #18808: wait for the thread state to be gone.
@@ -1196,9 +1203,19 @@ def _wait_for_tstate_lock(self, block=True, timeout=-1):
1196
1203
assert self ._is_stopped
1197
1204
return
1198
1205
1206
+ cur_thr_name = current_thread ()._name
1199
1207
try :
1200
1208
if lock .acquire (block , timeout ):
1209
+ self ._log (f"Acquired _tstate_lock for { self ._name } " )
1210
+ if cur_thr_name == "join-race-C" :
1211
+ self ._log ("Sleeping for 2" )
1212
+ time .sleep (2 )
1213
+ self ._log ("Releasing _tstate_lock" )
1201
1214
lock .release ()
1215
+ if cur_thr_name == "join-race-B" :
1216
+ self ._log ("Sleeping for 0.5" )
1217
+ time .sleep (0.5 )
1218
+ self ._log ("Calling _stop" )
1202
1219
self ._stop ()
1203
1220
except :
1204
1221
if lock .locked ():
0 commit comments