diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-08-19 22:37:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-19 22:37:17 (GMT) |
commit | d3dcc92778807ae8f7ebe85178f36a29711cd478 (patch) | |
tree | 9f416500ba67997ae72cda0594f5bcc62ac303b9 /Lib/threading.py | |
parent | cf9360e524acafdce99a8a1e48947fd7da06f3d4 (diff) | |
download | cpython-d3dcc92778807ae8f7ebe85178f36a29711cd478.zip cpython-d3dcc92778807ae8f7ebe85178f36a29711cd478.tar.gz cpython-d3dcc92778807ae8f7ebe85178f36a29711cd478.tar.bz2 |
bpo-37788: Fix a reference leak if a thread is not joined (GH-15228)
Add threading.Thread.__del__() method to ensure that the thread state
lock is removed from the _shutdown_locks list when a thread
completes.
Diffstat (limited to 'Lib/threading.py')
-rw-r--r-- | Lib/threading.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/threading.py b/Lib/threading.py index 32a3d7c..67e1c4f 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -806,6 +806,16 @@ class Thread: # For debugging and _after_fork() _dangling.add(self) + def __del__(self): + if not self._initialized: + return + lock = self._tstate_lock + if lock is not None and not self.daemon: + # ensure that self._tstate_lock is not in _shutdown_locks + # if join() was not called explicitly + with _shutdown_locks_lock: + _shutdown_locks.discard(lock) + def _reset_internal_locks(self, is_alive): # private! Called by _after_fork() to reset our internal locks as # they may be in an invalid state leading to a deadlock or crash. |