Skip to content

Commit bb4cecb

Browse files
Add the mainthreadonly arg to _PyEval_AddPendingCall().
1 parent 357e084 commit bb4cecb

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

Include/internal/pycore_ceval.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
2727
PyAPI_FUNC(int) _PyEval_AddPendingCall(
2828
PyInterpreterState *interp,
2929
int (*func)(void *),
30-
void *arg);
30+
void *arg,
31+
int mainthreadonly);
3132
PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyInterpreterState *interp);
3233
#ifdef HAVE_FORK
3334
extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);

Modules/signalmodule.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ trip_signal(int sig_num)
314314
still use it for this exceptional case. */
315315
_PyEval_AddPendingCall(interp,
316316
report_wakeup_send_error,
317-
(void *)(intptr_t) last_error);
317+
(void *)(intptr_t) last_error,
318+
1);
318319
}
319320
}
320321
}
@@ -333,7 +334,8 @@ trip_signal(int sig_num)
333334
still use it for this exceptional case. */
334335
_PyEval_AddPendingCall(interp,
335336
report_wakeup_write_error,
336-
(void *)(intptr_t)errno);
337+
(void *)(intptr_t)errno,
338+
1);
337339
}
338340
}
339341
}

Python/ceval_gil.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,10 @@ _pop_pending_call(struct _pending_calls *pending,
799799

800800
int
801801
_PyEval_AddPendingCall(PyInterpreterState *interp,
802-
int (*func)(void *), void *arg)
802+
int (*func)(void *), void *arg,
803+
int mainthreadonly)
803804
{
805+
assert(!mainthreadonly || _Py_IsMainInterpreter(interp));
804806
struct _pending_calls *pending = &interp->ceval.pending;
805807
/* Ensure that _PyEval_InitState() was called
806808
and that _PyEval_FiniState() is not called yet. */
@@ -843,7 +845,7 @@ Py_AddPendingCall(int (*func)(void *), void *arg)
843845
/* Last resort: use the main interpreter */
844846
interp = _PyInterpreterState_Main();
845847
}
846-
return _PyEval_AddPendingCall(interp, func, arg);
848+
return _PyEval_AddPendingCall(interp, func, arg, 1);
847849
}
848850

849851
static int

0 commit comments

Comments
 (0)