File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -738,6 +738,30 @@ def callback():
738
738
finally :
739
739
sys .settrace (old_trace )
740
740
741
+ @cpython_only
742
+ def test_shutdown_locks (self ):
743
+ for daemon in (False , True ):
744
+ with self .subTest (daemon = daemon ):
745
+ event = threading .Event ()
746
+ thread = threading .Thread (target = event .wait , daemon = daemon )
747
+
748
+ # Thread.start() must add lock to _shutdown_locks,
749
+ # but only for non-daemon thread
750
+ thread .start ()
751
+ tstate_lock = thread ._tstate_lock
752
+ if not daemon :
753
+ self .assertIn (tstate_lock , threading ._shutdown_locks )
754
+ else :
755
+ self .assertNotIn (tstate_lock , threading ._shutdown_locks )
756
+
757
+ # unblock the thread and join it
758
+ event .set ()
759
+ thread .join ()
760
+
761
+ # Thread._stop() must remove tstate_lock from _shutdown_locks.
762
+ # Daemon threads must never add it to _shutdown_locks.
763
+ self .assertNotIn (tstate_lock , threading ._shutdown_locks )
764
+
741
765
742
766
class ThreadJoinOnShutdown (BaseTestCase ):
743
767
Original file line number Diff line number Diff line change @@ -965,7 +965,7 @@ def _stop(self):
965
965
self ._tstate_lock = None
966
966
if not self .daemon :
967
967
with _shutdown_locks_lock :
968
- _shutdown_locks .discard (self . _tstate_lock )
968
+ _shutdown_locks .discard (lock )
969
969
970
970
def _delete (self ):
971
971
"Remove current thread from the dict of currently running threads."
You can’t perform that action at this time.
0 commit comments