# Daemon threads must never add it to _shutdown_locks.
self.assertNotIn(tstate_lock, threading._shutdown_locks)
+ def test_leak_without_join(self):
+ # bpo-37788: Test that a thread which is not joined explicitly
+ # does not leak. Test written for reference leak checks.
+ def noop(): pass
+ with support.wait_threads_exit():
+ threading.Thread(target=noop).start()
+ # Thread.join() is not called
+
class ThreadJoinOnShutdown(BaseTestCase):
# 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.