File tree Expand file tree Collapse file tree 3 files changed +19
-0
lines changed Expand file tree Collapse file tree 3 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -761,6 +761,14 @@ def test_shutdown_locks(self):
761
761
# Daemon threads must never add it to _shutdown_locks.
762
762
self .assertNotIn (tstate_lock , threading ._shutdown_locks )
763
763
764
+ def test_leak_without_join (self ):
765
+ # bpo-37788: Test that a thread which is not joined explicitly
766
+ # does not leak. Test written for reference leak checks.
767
+ def noop (): pass
768
+ with support .wait_threads_exit ():
769
+ threading .Thread (target = noop ).start ()
770
+ # Thread.join() is not called
771
+
764
772
765
773
class ThreadJoinOnShutdown (BaseTestCase ):
766
774
Original file line number Diff line number Diff line change @@ -806,6 +806,16 @@ class is implemented.
806
806
# For debugging and _after_fork()
807
807
_dangling .add (self )
808
808
809
+ def __del__ (self ):
810
+ if not self ._initialized :
811
+ return
812
+ lock = self ._tstate_lock
813
+ if lock is not None and not self .daemon :
814
+ # ensure that self._tstate_lock is not in _shutdown_locks
815
+ # if join() was not called explicitly
816
+ with _shutdown_locks_lock :
817
+ _shutdown_locks .discard (lock )
818
+
809
819
def _reset_internal_locks (self , is_alive ):
810
820
# private! Called by _after_fork() to reset our internal locks as
811
821
# they may be in an invalid state leading to a deadlock or crash.
Original file line number Diff line number Diff line change
1
+ Fix a reference leak if a thread is not joined.
You can’t perform that action at this time.
0 commit comments