Skip to content

Commit 317bab0

Browse files
authored
PyOS_AfterFork_Child() pass tstate to _PyEval_ReInitThreads() (GH-20598)
1 parent 45b34a0 commit 317bab0

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ PyAPI_FUNC(int) _PyEval_AddPendingCall(
2525
void *arg);
2626
PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyThreadState *tstate);
2727
#ifdef HAVE_FORK
28-
extern PyStatus _PyEval_ReInitThreads(struct pyruntimestate *runtime);
28+
extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
2929
#endif
3030
PyAPI_FUNC(void) _PyEval_SetCoroutineOriginTrackingDepth(
3131
PyThreadState *tstate,

Modules/posixmodule.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,10 @@ PyOS_AfterFork_Child(void)
470470
goto fatal_error;
471471
}
472472

473-
status = _PyEval_ReInitThreads(runtime);
473+
PyThreadState *tstate = _PyThreadState_GET();
474+
_Py_EnsureTstateNotNULL(tstate);
475+
476+
status = _PyEval_ReInitThreads(tstate);
474477
if (_PyStatus_EXCEPTION(status)) {
475478
goto fatal_error;
476479
}
@@ -491,8 +494,9 @@ PyOS_AfterFork_Child(void)
491494
if (_PyStatus_EXCEPTION(status)) {
492495
goto fatal_error;
493496
}
497+
assert(_PyThreadState_GET() == tstate);
494498

495-
run_at_forkers(_PyInterpreterState_GET()->after_forkers_child, 0);
499+
run_at_forkers(tstate->interp->after_forkers_child, 0);
496500
return;
497501

498502
fatal_error:

Python/ceval.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,9 @@ PyEval_ReleaseThread(PyThreadState *tstate)
436436
which are not running in the child process, and clear internal locks
437437
which might be held by those threads. */
438438
PyStatus
439-
_PyEval_ReInitThreads(_PyRuntimeState *runtime)
439+
_PyEval_ReInitThreads(PyThreadState *tstate)
440440
{
441-
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
442-
_Py_EnsureTstateNotNULL(tstate);
441+
_PyRuntimeState *runtime = tstate->interp->runtime;
443442

444443
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
445444
struct _gil_runtime_state *gil = &tstate->interp->ceval.gil;

0 commit comments

Comments
 (0)