This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2019-11-07.11:45:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1573127151.38.0.779542289118.issue38733@roundup.psfhosted.org>
In-reply-to
Content
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 <vstinner@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);
    }
History
Date User Action Args
2019-11-07 11:45:51vstinnersetrecipients: + vstinner
2019-11-07 11:45:51vstinnersetmessageid: <1573127151.38.0.779542289118.issue38733@roundup.psfhosted.org>
2019-11-07 11:45:51vstinnerlinkissue38733 messages
2019-11-07 11:45:51vstinnercreate