From f86bbd9a9bb350a60512ca9883185b629c050519 Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Sun, 8 Nov 2026 21:59:20 -0700 Subject: [PATCH 1/2] gh-158194: Exercise type freezing in concurrent setattr deadlock test --- Lib/test/test_free_threading/test_type.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_free_threading/test_type.py b/Lib/test/test_free_threading/test_type.py index 6e750e0bc6084e..46f0cf2db4c29a 100644 --- a/Lib/test/test_free_threading/test_type.py +++ b/Lib/test/test_free_threading/test_type.py @@ -375,6 +375,7 @@ def test_concurrent_setattr_deadlock(self): # dict mutex and waited for the type lock. # This is fairly difficult to trigger the race but this N seems to do # it at least sometimes. + type_freeze = import_helper.import_module("_testlimitedcapi").type_freeze N = 200 done = False @@ -401,6 +402,15 @@ def lister(): while not done: Base.__subclasses__() + def freezer(): + # gh-158194: Freezing must keep the type lock pinned while + # waiting for stop-the-world, just like slot updates do. + barrier.wait() + for _ in range(10): + class Frozen: + pass + type_freeze(Frozen) + def basesetter(): nonlocal done barrier.wait() @@ -418,7 +428,7 @@ class B(A): # to keep the type lock and the stop-the-world mutex contended, which # is what gets the setters into the window where it happens. targets = (setter, setter, subclasser, subclasser, - lister, lister, basesetter) + lister, lister, basesetter, freezer) barrier = threading.Barrier(len(targets)) threads = [Thread(target=target) for target in targets] with threading_helper.start_threads(threads): From 78fad9215de084b3df43a4e0d66b9f9e09bdc336 Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Sun, 8 Nov 2026 22:04:55 -0700 Subject: [PATCH 2/2] Fix comment, we don't pin type lock anymore. --- Lib/test/test_free_threading/test_type.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_free_threading/test_type.py b/Lib/test/test_free_threading/test_type.py index 46f0cf2db4c29a..f7e4adf2e02ce8 100644 --- a/Lib/test/test_free_threading/test_type.py +++ b/Lib/test/test_free_threading/test_type.py @@ -403,8 +403,8 @@ def lister(): Base.__subclasses__() def freezer(): - # gh-158194: Freezing must keep the type lock pinned while - # waiting for stop-the-world, just like slot updates do. + # gh-158194: Exercise type freezing concurrently with slot + # updates and competing stop-the-world requests. barrier.wait() for _ in range(10): class Frozen: