faulthandler now works in non-Python threads
Issue #26563:
* Add _PyGILState_GetInterpreterStateUnsafe() function: the single
PyInterpreterState used by this process' GILState implementation.
* Enhance _Py_DumpTracebackThreads() to retrieve the interpreter state from
autoInterpreterState in last resort. The function now accepts NULL for interp
and current_tstate parameters.
* test_faulthandler: fix a ResourceWarning when test is interrupted by CTRL+c
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 4fc6a15..41528cd 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1275,25 +1275,11 @@
static void
_Py_FatalError_DumpTracebacks(int fd)
{
- PyThreadState *tstate;
-
-#ifdef WITH_THREAD
- /* PyGILState_GetThisThreadState() works even if the GIL was released */
- tstate = PyGILState_GetThisThreadState();
-#else
- tstate = PyThreadState_GET();
-#endif
- if (tstate == NULL) {
- /* _Py_DumpTracebackThreads() requires the thread state to display
- * frames */
- return;
- }
-
fputc('\n', stderr);
fflush(stderr);
/* display the current Python stack */
- _Py_DumpTracebackThreads(fd, tstate->interp, tstate);
+ _Py_DumpTracebackThreads(fd, NULL, NULL);
}
/* Print the current exception (if an exception is set) with its traceback,