gh-130522: Fix unraisable TypeError in threading at interpreter shutdown (#131537)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
This commit is contained in:
Tyler Kennedy 2025-07-25 10:51:30 -04:00 committed by GitHub
parent 7ce2f101c4
commit cb93b6fc5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 1 deletions

View file

@ -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):