Skip to content

Commit 426628d

Browse files
Always use the main interpreter for Py_AddPendingCall().
1 parent bb4cecb commit 426628d

File tree

1 file changed

+2
-25
lines changed

1 file changed

+2
-25
lines changed

Python/ceval_gil.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -820,31 +820,8 @@ _PyEval_AddPendingCall(PyInterpreterState *interp,
820820
int
821821
Py_AddPendingCall(int (*func)(void *), void *arg)
822822
{
823-
/* Best-effort to support subinterpreters and calls with the GIL released.
824-
825-
First attempt _PyThreadState_GET() since it supports subinterpreters.
826-
827-
If the GIL is released, _PyThreadState_GET() returns NULL . In this
828-
case, use PyGILState_GetThisThreadState() which works even if the GIL
829-
is released.
830-
831-
Sadly, PyGILState_GetThisThreadState() doesn't support subinterpreters:
832-
see bpo-10915 and bpo-15751.
833-
834-
Py_AddPendingCall() doesn't require the caller to hold the GIL. */
835-
PyThreadState *tstate = _PyThreadState_GET();
836-
if (tstate == NULL) {
837-
tstate = PyGILState_GetThisThreadState();
838-
}
839-
840-
PyInterpreterState *interp;
841-
if (tstate != NULL) {
842-
interp = tstate->interp;
843-
}
844-
else {
845-
/* Last resort: use the main interpreter */
846-
interp = _PyInterpreterState_Main();
847-
}
823+
/* Legacy users of this API will continue to target the main thread. */
824+
PyInterpreterState *interp = _PyInterpreterState_Main();
848825
return _PyEval_AddPendingCall(interp, func, arg, 1);
849826
}
850827

0 commit comments

Comments
 (0)