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 eric.snow, vstinner
Date 2020-03-18.00:42:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
In the master branch of Python, trip_signal() calls _PyEval_AddPendingCall(tstate) and tstate is get using _PyRuntimeState_GetThreadState(runtime).

trip_signal() can be called while the GIL is not held: tstate is NULL in this case. For example, it's the case when calling signal.raise_signal().

Problem: _PyEval_AddPendingCall() uses tstate if pending->finishing is non-zero.

    if (pending->finishing) {
        _PyErr_Fetch(tstate, &exc, &val, &tb);
        _PyErr_SetString(tstate, PyExc_SystemError,
                        "Py_AddPendingCall: cannot add pending calls "
                        "(Python shutting down)");

pending->finishing was addd in bpo-33608 by the change:

commit 842a2f07f2f08a935ef470bfdaeef40f87490cfc
Author: Eric Snow <>
Date:   Fri Mar 15 15:47:51 2019 -0600

    bpo-33608: Deal with pending calls relative to runtime shutdown. (gh-12246)

I found this issue while trying to make pending calls per interpreter in bpo-39984: move pending from _PyRuntimeState to PyInterpreterState.
Date User Action Args
2020-03-18 00:42:09vstinnersetrecipients: + vstinner, eric.snow
2020-03-18 00:42:09vstinnersetmessageid: <>
2020-03-18 00:42:09vstinnerlinkissue37127 messages
2020-03-18 00:42:09vstinnercreate