Skip to content

gh-156910: Add free-threading regression test for type_set_abstractmethods() deadlock - #161195

Open
davidwelling2 wants to merge 1 commit into
python:mainfrom
davidwelling2:gh-156910-abstractmethods-test
Open

davidwelling2 wants to merge 1 commit into
python:mainfrom
davidwelling2:gh-156910-abstractmethods-test

Conversation

@davidwelling2

@davidwelling2 davidwelling2 commented Nov 2, 2026 •

Copy link
Copy Markdown

Follow-up to gh-156948, which fixed the deadlock but didn't add a test.

This adds test_abstractmethods_and_register to test_free_threading/test_type.py. It races ABC class
creation (type_set_abstractmethods() stops the world under TYPE_LOCK) against
collections.abc.Sequence.register() (_PyType_SetFlagsRecursive() stops the world with TYPE_LOCK
pinned), with a gc.collect() thread to add contention on the stop-the-world mutex.

Tested on a --disable-gil --with-pydebug build: on main before gh-159972, reverting the
Objects/typeobject.c change from gh-156948 made the test hang in 7/7 runs (killed at 120s);
with it, it passed 20/20 (~2s each). It also passes 20/20 on current main after gh-159972
(gh-158195), which reworked how TYPE_LOCK interacts with stop-the-world, so the test now
guards both fixes.

This should be backported to 3.15 only. 3.14's type_set_abstractmethods() doesn't stop the world,
so it doesn't have this bug.

AI assistance was used in preparing this change; I have reviewed and tested it.

@python-cla-bot

python-cla-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@davidwelling2
davidwelling2 force-pushed the gh-156910-abstractmethods-test branch from 241b0fc to c3d4f27 Compare November 2, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant