https://github.com/python/cpython/commit/44f314933cc86a23b07c5e8df95d5ba425103840
commit: 44f314933cc86a23b07c5e8df95d5ba425103840
branch: 3.13
author: Armaan Vakharia <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2026-05-19T15:04:13Z
summary:

[3.13] gh-149590: Remove faulthandler_traverse (GH-150023) (#150087)

`faulthandler_traverse` visits Python objects owned by `_PyRuntime`, not
by the module instance. With multi-phase init allowing multiple module
instances, each instance's GC traversal decrements `gc_refs` on the same
runtime-owned objects, driving it negative when two instances are
collected simultaneously.
(cherry picked from commit 56737483c2ffdaadfec648fd38d409c6b10941c0)

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-05-18-13-47-17.gh-issue-149590.IPBeQx.rst
M Modules/faulthandler.c

diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-05-18-13-47-17.gh-issue-149590.IPBeQx.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-05-18-13-47-17.gh-issue-149590.IPBeQx.rst
new file mode 100644
index 00000000000000..8d3b29d69cc857
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-05-18-13-47-17.gh-issue-149590.IPBeQx.rst
@@ -0,0 +1 @@
+Fix crash when faulthandler is imported more than once.
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index 5a4efed9946fba..42521e40ba7b2f 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -1180,20 +1180,6 @@ faulthandler_stack_overflow(PyObject *self, PyObject 
*Py_UNUSED(ignored))
 #endif   /* defined(FAULTHANDLER_USE_ALT_STACK) && defined(HAVE_SIGACTION) */
 
 
-static int
-faulthandler_traverse(PyObject *module, visitproc visit, void *arg)
-{
-    Py_VISIT(thread.file);
-#ifdef FAULTHANDLER_USER
-    if (user_signals != NULL) {
-        for (size_t signum=0; signum < Py_NSIG; signum++)
-            Py_VISIT(user_signals[signum].file);
-    }
-#endif
-    Py_VISIT(fatal_error.file);
-    return 0;
-}
-
 #ifdef MS_WINDOWS
 static PyObject *
 faulthandler_raise_exception(PyObject *self, PyObject *args)
@@ -1322,7 +1308,6 @@ static struct PyModuleDef module_def = {
     .m_name = "faulthandler",
     .m_doc = module_doc,
     .m_methods = module_methods,
-    .m_traverse = faulthandler_traverse,
     .m_slots = faulthandler_slots
 };
 

_______________________________________________
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