mirror of
https://github.com/python/cpython.git
synced 2025-10-04 22:20:46 +00:00
[3.9] bpo-37788: Fix reference leak when Thread is never joined (GH-26103) (GH-26142)
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 c10c2ec7a0
)
Co-authored-by: Antoine Pitrou <antoine@python.org>
Automerge-Triggered-By: GH:pitrou
This commit is contained in:
parent
fa9de0c383
commit
b30b25b266
3 changed files with 27 additions and 1 deletions
|
@ -805,6 +805,14 @@ class ThreadTests(BaseTestCase):
|
|||
""")
|
||||
self.assertEqual(out.rstrip(), b"thread_dict.atexit = 'value'")
|
||||
|
||||
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):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue