summaryrefslogtreecommitdiff
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-05-15 02:24:44 -0700
committerGitHub <noreply@github.com>2021-05-15 02:24:44 -0700
commit71dca6ea73aaf215fafa094512e8c748248c16b0 (patch)
tree848a16f29f4098ea9e81e2ff6e88540920563e72 /Lib/test/test_threading.py
parent2e99869f64bbd3c6590cb5ceaf9cf59e63689d63 (diff)
downloadcpython-git-71dca6ea73aaf215fafa094512e8c748248c16b0.tar.gz
[3.10] bpo-37788: Fix reference leak when Thread is never joined (GH-26103) (GH-26138)
When a Thread is not joined after it has stopped, its lock may remain in the _shutdown_locks set until interpreter shutdown. If many threads are created this way, the _shutdown_locks set could therefore grow endlessly. To avoid such a situation, purge expired locks each time a new one is added or removed. (cherry picked from commit c10c2ec7a0e06975e8010c56c9c3270f8ea322ec) Co-authored-by: Antoine Pitrou <antoine@python.org>
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r--Lib/test/test_threading.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 546773e332..08c0ccd9a7 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -907,6 +907,13 @@ class ThreadTests(BaseTestCase):
thread.join()
self.assertTrue(target.ran)
+ 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 threading_helper.wait_threads_exit():
+ threading.Thread(target=noop).start()
+ # Thread.join() is not called
class ThreadJoinOnShutdown(BaseTestCase):