mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[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 c10c2ec7a0)
Co-authored-by: Antoine Pitrou <antoine@python.org>
This commit is contained in:
parent
2e99869f64
commit
71dca6ea73
3 changed files with 26 additions and 1 deletions
|
|
@ -907,6 +907,13 @@ def __call__(self):
|
|||
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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue