Skip to content

Commit dd0c198

Browse files
gh-132578: Add regression test ensuring Thread subclasses can safely define _handle
1 parent fad0674 commit dd0c198

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lib/test/test_threading.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,5 +2847,25 @@ def run_last():
28472847
err.decode())
28482848

28492849

2850+
class ThreadHandleRegressionTest(unittest.TestCase):
2851+
def test_subclass_can_define_handle(self):
2852+
# gh-132578: Ensure third-party libraries overriding or defining
2853+
# a custom `_handle` attribute/method don't clash with CPython internal implementation details.
2854+
class CustomThread(threading.Thread):
2855+
def __init__(self):
2856+
super().__init__()
2857+
self._handle = "custom_third_party_handle_value"
2858+
2859+
def run(self):
2860+
pass
2861+
2862+
t = CustomThread()
2863+
t.start()
2864+
t.join()
2865+
2866+
# Assert that our custom handle parameter was preserved and did not break the thread run lifecycle
2867+
self.assertEqual(t._handle, "custom_third_party_handle_value")
2868+
2869+
28502870
if __name__ == "__main__":
28512871
unittest.main()

0 commit comments

Comments
 (0)