STINNER Victor <vstin...@python.org> added the comment:
In 2018 with bpo-26558, I fixed Py_FatalError() to no longer access the current exception of the current Python thread state, if the current thread doesn't not hold the GIL: commit 3a228ab17c2a9cffd1a2f15f30d6209768de20a6 Author: Victor Stinner <vstin...@redhat.com> Date: Thu Nov 1 00:26:41 2018 +0100 bpo-26558: Fix Py_FatalError() with GIL released (GH-10267) Don't call _Py_FatalError_PrintExc() nor flush_std_files() if the current thread doesn't hold the GIL, or if the current thread has no Python state thread. Extract of Py_FatalError() code: /* Check if the current thread has a Python thread state and holds the GIL. tss_tstate is NULL if Py_FatalError() is called from a C thread which has no Python thread state. tss_tstate != tstate if the current Python thread does not hold the GIL. */ PyThreadState *tss_tstate = PyGILState_GetThisThreadState(); 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(fd)) { /* No exception is set, or an exception is set without traceback */ _Py_FatalError_DumpTracebacks(fd, interp, tss_tstate); } } else { _Py_FatalError_DumpTracebacks(fd, interp, tss_tstate); } ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38733> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com