Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
@@ -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.
Loading