mirror of
https://github.com/python/cpython.git
synced 2025-10-27 11:44:39 +00:00
[3.14] gh-130522: Fix unraisable TypeError in threading at interpreter shutdown (GH-131537) (#137105)
Co-authored-by: Tyler Kennedy <tk@tkte.ch> Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
This commit is contained in:
parent
134ca903b3
commit
f4870086ba
3 changed files with 20 additions and 1 deletions
|
|
@ -1993,6 +1993,23 @@ def modify_file():
|
||||||
t.start()
|
t.start()
|
||||||
t.join()
|
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):
|
class ThreadRunFail(threading.Thread):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
|
||||||
|
|
@ -1421,7 +1421,7 @@ def __init__(self, dummy_thread):
|
||||||
# the related _DummyThread will be kept forever!
|
# the related _DummyThread will be kept forever!
|
||||||
_thread_local_info._track_dummy_thread_ref = self
|
_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:
|
with _active_limbo_lock:
|
||||||
if _active.get(self._tident) is self._dummy_thread:
|
if _active.get(self._tident) is self._dummy_thread:
|
||||||
_active.pop(self._tident, None)
|
_active.pop(self._tident, None)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix unraisable :exc:`TypeError` raised during :term:`interpreter shutdown`
|
||||||
|
in the :mod:`threading` module.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue