Skip to content

Commit cb93b6f

Browse files
gh-130522: Fix unraisable TypeError in threading at interpreter shutdown (#131537)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent 7ce2f10 commit cb93b6f

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Lib/test/test_threading.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,23 @@ def modify_file():
20422042
t.start()
20432043
t.join()
20442044

2045+
def test_dummy_thread_on_interpreter_shutdown(self):
2046+
# GH-130522: When `threading` held a reference to itself and then a
2047+
# _DummyThread() object was created, destruction of the dummy thread
2048+
# would emit an unraisable exception at shutdown, due to a lock being
2049+
# destroyed.
2050+
code = """if True:
2051+
import sys
2052+
import threading
2053+
2054+
threading.x = sys.modules[__name__]
2055+
x = threading._DummyThread()
2056+
"""
2057+
rc, out, err = assert_python_ok("-c", code)
2058+
self.assertEqual(rc, 0)
2059+
self.assertEqual(out, b"")
2060+
self.assertEqual(err, b"")
2061+
20452062

20462063
class ThreadRunFail(threading.Thread):
20472064
def run(self):

Lib/threading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ def __init__(self, dummy_thread):
14141414
# the related _DummyThread will be kept forever!
14151415
_thread_local_info._track_dummy_thread_ref = self
14161416

1417-
def __del__(self):
1417+
def __del__(self, _active_limbo_lock=_active_limbo_lock, _active=_active):
14181418
with _active_limbo_lock:
14191419
if _active.get(self._tident) is self._dummy_thread:
14201420
_active.pop(self._tident, None)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix unraisable :exc:`TypeError` raised during :term:`interpreter shutdown`
2+
in the :mod:`threading` module.

0 commit comments

Comments
 (0)
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