Skip to content

gh-130522: Fix threading errors during garbage collection #131537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 25, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-130522: Fix threading errors during garbage collection
This issue was introduced in 3.13 (5a1ecc8) and causes spurious errors when threads shutdown. This issue occurs on all platforms, and can be triggered by utilities like `coverage.py`'s pytracer module or the PyCharm debugger (pydevd), which may keep references to internal threading objects around.


Issue was reproduced on Linux/OSX/Windows:

```
Exception ignored in: <function _DeleteDummyThreadOnDel.__del__ at 0x10a0811c0>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/threading.py", line 1383, in __del__
TypeError: 'NoneType' object does not support the context manager protocol
```

```
 Exception ignored in: <function _DeleteDummyThreadOnDel.__del__ at 0x7fedc963ff60>
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/threading.py", line 1383, in __del__
TypeError: 'NoneType' object does not support the context manager protocol
```

```
 Exception ignored in: <function _DeleteDummyThreadOnDel.__del__ at 0x000001A6B07BA840>
Traceback (most recent call last):
  File "C:\hostedtoolcache\windows\Python\3.13.2\x64\Lib\threading.py", line 1383, in __del__
TypeError: 'NoneType' object does not support the context manager protocol
```
  • Loading branch information
TkTech authored Mar 21, 2025
commit ec00e4cb0562af7ad2f21e795ea8a7c42918d59f
2 changes: 1 addition & 1 deletion Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ def __init__(self, dummy_thread):
# the related _DummyThread will be kept forever!
_thread_local_info._track_dummy_thread_ref = self

def __del__(self):
def __del__(self, _active_limbo_lock=_active_limbo_lock, _active=_active):
with _active_limbo_lock:
if _active.get(self._tident) is self._dummy_thread:
_active.pop(self._tident, None)
Expand Down
Loading