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
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 17 additions & 0 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,23 @@ def modify_file():
t.start()
t.join()

def test_dummy_thread_on_interpreter_shutdown(self):
# GH-130522: When `threading` held a reference to itself and then a
# _DummyThread() object was created, destruction of the dummy thread
# would emit an unraisable exception at shutdown, due to a lock being
# destroyed.
code = """if True:
import sys
import threading
threading.x = sys.modules[__name__]
x = threading._DummyThread()
"""
rc, out, err = assert_python_ok("-c", code)
self.assertEqual(rc, 0)
self.assertEqual(out, b"")
self.assertEqual(err, b"")


class ThreadRunFail(threading.Thread):
def run(self):
Expand Down
2 changes: 1 addition & 1 deletion Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix unraisable :exc:`TypeError` raised during :term:`interpreter shutdown`
in the :mod:`threading` module.
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy