https://github.com/python/cpython/commit/1ac3bfaacc424775438f5873fa178a93a53edef2
commit: 1ac3bfaacc424775438f5873fa178a93a53edef2
branch: main
author: Kumar Aditya <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2026-09-09T11:50:58+05:30
summary:

gh-156910: fix deadlock in type_set_abstractmethods under free-threading 
(#156948)

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 000000000000000..f717bbe5f16aa96
--- /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 572e302df8d80d5..30958310227af0e 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1706,14 +1706,17 @@ type_set_abstractmethods(PyObject *tp, PyObject *value, 
void *Py_UNUSED(closure)
         return -1;
     }
 
+    pinned_mutexes_t pinned;
     BEGIN_TYPE_LOCK();
     _PyType_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]

Reply via email to