diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index c28a28e3bdad17..82ab340c8434c1 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -3484,7 +3484,8 @@ fatal_output_debug(const char *msg) static void -fatal_error_dump_runtime(int fd, _PyRuntimeState *runtime) +fatal_error_dump_runtime(int fd, _PyRuntimeState *runtime, + PyInterpreterState *interp) { PUTS(fd, "Python runtime state: "); PyThreadState *finalizing = _PyRuntimeState_GetFinalizing(runtime); @@ -3493,6 +3494,9 @@ fatal_error_dump_runtime(int fd, _PyRuntimeState *runtime) _Py_DumpHexadecimal(fd, (uintptr_t)finalizing, sizeof(finalizing) * 2); PUTS(fd, ")"); } + else if (interp != NULL && interp->finalizing) { + PUTS(fd, "finalizing"); + } else if (_PyRuntimeState_GetInitialized(runtime)) { PUTS(fd, "initialized"); } @@ -3698,9 +3702,6 @@ fatal_error(int fd, int header, const char *prefix, const char *msg, PUTS(fd, "\n"); } - _PyRuntimeState *runtime = &_PyRuntime; - fatal_error_dump_runtime(fd, runtime); - /* Check if the current thread has a Python thread state and holds the GIL. @@ -3718,8 +3719,11 @@ fatal_error(int fd, int header, const char *prefix, const char *msg, else if (tss_tstate != NULL) { interp = tss_tstate->interp; } - int has_tstate_and_gil = (tss_tstate != NULL && tss_tstate == tstate); + _PyRuntimeState *runtime = &_PyRuntime; + fatal_error_dump_runtime(fd, runtime, interp); + + int has_tstate_and_gil = (tss_tstate != NULL && tss_tstate == tstate); if (has_tstate_and_gil) { /* If an exception is set, print the exception with its traceback */ if (!_Py_FatalError_PrintExc(tss_tstate)) {