bpo-37788: Fix a reference leak if a thread is not joined#15228
Conversation
Add threading.Thread.__del__() method to ensure that the thread state lock is removed from the _shutdown_locks list when a thread completes.
|
I have two points:
|
|
@pitrou, @pablogsal, @methane, @serhiy-storchaka: my https://bugs.python.org/issue36402 fix introduced a memory leak when a thread is started but never joined explicitly. This PR adds a destructor to thread.Thread to fix the regression. What do you think? We need to fix 3.7, 3.8 and master branches, I would prefer to use the same fix in all branches. |
|
|
That hasn't been the case in a long time, except if you're talking about Python 2.7. |
|
So we can now get rid of |
|
Hmm... probably? I'll let you figure out :-) |
|
That code was added after 2.7, it was not the first attempt to fix some issues with tempfile, and only it was successful. |
That's no longer the case since @pitrou's PEP 442 https://www.python.org/dev/peps/pep-0442/ (finalizers). |
|
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8. |
|
I'm having trouble backporting to |
|
GH-15336 is a backport of this pull request to the 3.7 branch. |
|
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
|
GH-15337 is a backport of this pull request to the 3.8 branch. |
|
Oh, my change is wrong: it introduced a regression :-( |
…5228) Add threading.Thread.__del__() method to ensure that the thread state lock is removed from the _shutdown_locks list when a thread completes.
…thonGH-15228)" (pythonGH-15338) This reverts commit d3dcc92.
…5228) Add threading.Thread.__del__() method to ensure that the thread state lock is removed from the _shutdown_locks list when a thread completes.
…thonGH-15228)" (pythonGH-15338) This reverts commit d3dcc92.
…5228) Add threading.Thread.__del__() method to ensure that the thread state lock is removed from the _shutdown_locks list when a thread completes.
…thonGH-15228)" (pythonGH-15338) This reverts commit d3dcc92.
|
Any movement on fixing this leak when threads aren't "join"-ed? I couldn't upgrade to 3.7 because of this leak, Thanks for all your work on Python, I see you've been quick active in making it better. |
Add threading.Thread.del() method to ensure that the thread state
lock is removed from the _shutdown_locks list when a thread
completes.
https://bugs.python.org/issue37788