Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions Python/ceval_gil.c
Original file line number Diff line number Diff line change
Expand Up @@ -991,12 +991,34 @@ _Py_FinishPendingCalls(PyThreadState *tstate)
assert(PyGILState_Check());
assert(_PyThreadState_CheckConsistency(tstate));

if (make_pending_calls(tstate) < 0) {
PyObject *exc = _PyErr_GetRaisedException(tstate);
PyErr_BadInternalCall();
_PyErr_ChainExceptions1(exc);
_PyErr_Print(tstate);
}
struct _pending_calls *pending = &tstate->interp->ceval.pending;
struct _pending_calls *pending_main =
_Py_IsMainThread() && _Py_IsMainInterpreter(tstate->interp)
? &_PyRuntime.ceval.pending_mainthread
: NULL;
/* make_pending_calls() may return early without making all pending
calls, so we keep trying until we're actually done. */
int32_t npending;
#ifndef NDEBUG
int32_t npending_prev = INT32_MAX;
#endif
do {
if (make_pending_calls(tstate) < 0) {
PyObject *exc = _PyErr_GetRaisedException(tstate);
PyErr_BadInternalCall();
_PyErr_ChainExceptions1(exc);
_PyErr_Print(tstate);
}

npending = _Py_atomic_load_int32_relaxed(&pending->npending);
if (pending_main != NULL) {
npending += _Py_atomic_load_int32_relaxed(&pending_main->npending);
}
#ifndef NDEBUG
assert(npending_prev > npending);
npending_prev = npending;
#endif
} while (npending > 0);
}

int
Expand Down