Skip to content

Commit 4000dcd

Browse files
Prevent adding pending calls if finalizing.
1 parent 74f6568 commit 4000dcd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Python/ceval.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,17 @@ _pop_pending_call(int (**func)(void *), void **arg)
365365
int
366366
Py_AddPendingCall(int (*func)(void *), void *arg)
367367
{
368+
if (_PyRuntime.finalizing) {
369+
PyObject *exc, *val, *tb;
370+
PyErr_Fetch(&exc, &val, &tb);
371+
PyErr_SetString(PyExc_SystemError,
372+
"Py_AddPendingCall: cannot add pending calls "
373+
"(Python shutting down)");
374+
PyErr_Print();
375+
PyErr_Restore(exc, val, tb);
376+
return -1;
377+
}
378+
368379
PyThread_acquire_lock(_PyRuntime.ceval.pending.lock, WAIT_LOCK);
369380
int result = _push_pending_call(func, arg);
370381
PyThread_release_lock(_PyRuntime.ceval.pending.lock);

0 commit comments

Comments
 (0)