https://github.com/python/cpython/commit/090b5cd15322ae99c28f9aaa8017f680845db634
commit: 090b5cd15322ae99c28f9aaa8017f680845db634
branch: 3.15
author: Kumar Aditya <[email protected]>
committer: hugovk <[email protected]>
date: 2026-09-11T09:28:36+03:00
summary:
[3.15] gh-156910: fix deadlock in type_set_abstractmethods under free-threading
(#156948) (#157203)
gh-156910: fix deadlock in type_set_abstractmethods under free-threading
(#156948)
(cherry picked from commit 1ac3bfaacc424775438f5873fa178a93a53edef2)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2026-09-04-22-00-00.gh-issue-156910.aBcD3f.rst
M Objects/typeobject.c
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2026-09-04-22-00-00.gh-issue-156910.aBcD3f.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2026-09-04-22-00-00.gh-issue-156910.aBcD3f.rst
new file mode 100644
index 00000000000000..f717bbe5f16aa9
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2026-09-04-22-00-00.gh-issue-156910.aBcD3f.rst
@@ -0,0 +1,3 @@
+Fix a deadlock in the :term:`free threaded <free threading>` build when
+setting ``__abstractmethods__`` on a type while another thread holds the
+type lock.
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 0d3f98ff446aac..1d8e3dd1ef9d35 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1776,14 +1776,17 @@ type_set_abstractmethods(PyObject *tp, PyObject *value,
void *Py_UNUSED(closure)
return -1;
}
+ pinned_mutexes_t pinned;
BEGIN_TYPE_LOCK();
type_modified_unlocked(type);
+ type_lock_prevent_release(&pinned);
types_stop_world();
if (abstract)
type_add_flags(type, Py_TPFLAGS_IS_ABSTRACT);
else
type_clear_flags(type, Py_TPFLAGS_IS_ABSTRACT);
types_start_world();
+ type_lock_allow_release(&pinned);
ASSERT_TYPE_LOCK_HELD();
END_TYPE_LOCK();
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]