diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 3d01804513bde9..71756d64068be5 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -2847,5 +2847,25 @@ def run_last(): err.decode()) +class ThreadHandleRegressionTest(unittest.TestCase): + def test_subclass_can_define_handle(self): + # gh-132578: Ensure third-party libraries overriding or defining + # a custom `_handle` attribute/method don't clash with CPython internal implementation details. + class CustomThread(threading.Thread): + def __init__(self): + super().__init__() + self._handle = "custom_third_party_handle_value" + + def run(self): + pass + + t = CustomThread() + t.start() + t.join() + + # Assert that our custom handle parameter was preserved and did not break the thread run lifecycle + self.assertEqual(t._handle, "custom_third_party_handle_value") + + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS.d/next/Library/2026-05-24-01-30-00.gh-issue-132578.aBcDeF.rst b/Misc/NEWS.d/next/Library/2026-05-24-01-30-00.gh-issue-132578.aBcDeF.rst new file mode 100644 index 00000000000000..c4c926a9743995 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-05-24-01-30-00.gh-issue-132578.aBcDeF.rst @@ -0,0 +1 @@ +Add a regression test to ensure that custom user-defined subclasses of threading.Thread can safely define or override a custom _handle attribute without colliding with internal state-tracking implementations.