[Python-checkins] PyOS_AfterFork_Child() pass tstate to _PyEval_ReInitThreads() (GH-20598)

Victor Stinner webhook-mailer at python.org
Tue Jun 2 12:45:03 EDT 2020


https://github.com/python/cpython/commit/317bab0bf61e4cbab37c81baf185d8b57ca62a6b
commit: 317bab0bf61e4cbab37c81baf185d8b57ca62a6b
branch: master
author: Victor Stinner <vstinner at python.org>
committer: GitHub <noreply at github.com>
date: 2020年06月02日T18:44:54+02:00
summary:
PyOS_AfterFork_Child() pass tstate to _PyEval_ReInitThreads() (GH-20598)
files:
M Include/internal/pycore_ceval.h
M Modules/posixmodule.c
M Python/ceval.c
diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h
index 2da0154525b1c..aafb533b57d5f 100644
--- a/Include/internal/pycore_ceval.h
+++ b/Include/internal/pycore_ceval.h
@@ -25,7 +25,7 @@ PyAPI_FUNC(int) _PyEval_AddPendingCall(
 void *arg);
 PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyThreadState *tstate);
 #ifdef HAVE_FORK
-extern PyStatus _PyEval_ReInitThreads(struct pyruntimestate *runtime);
+extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
 #endif
 PyAPI_FUNC(void) _PyEval_SetCoroutineOriginTrackingDepth(
 PyThreadState *tstate,
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index afb6d183077a1..79779bfdeafd3 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -470,7 +470,10 @@ PyOS_AfterFork_Child(void)
 goto fatal_error;
 }
 
- status = _PyEval_ReInitThreads(runtime);
+ PyThreadState *tstate = _PyThreadState_GET();
+ _Py_EnsureTstateNotNULL(tstate);
+
+ status = _PyEval_ReInitThreads(tstate);
 if (_PyStatus_EXCEPTION(status)) {
 goto fatal_error;
 }
@@ -491,8 +494,9 @@ PyOS_AfterFork_Child(void)
 if (_PyStatus_EXCEPTION(status)) {
 goto fatal_error;
 }
+ assert(_PyThreadState_GET() == tstate);
 
- run_at_forkers(_PyInterpreterState_GET()->after_forkers_child, 0);
+ run_at_forkers(tstate->interp->after_forkers_child, 0);
 return;
 
 fatal_error:
diff --git a/Python/ceval.c b/Python/ceval.c
index 5edcfe354054a..9ab8329d6d8e7 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -436,10 +436,9 @@ PyEval_ReleaseThread(PyThreadState *tstate)
 which are not running in the child process, and clear internal locks
 which might be held by those threads. */
 PyStatus
-_PyEval_ReInitThreads(_PyRuntimeState *runtime)
+_PyEval_ReInitThreads(PyThreadState *tstate)
 {
- PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
- _Py_EnsureTstateNotNULL(tstate);
+ _PyRuntimeState *runtime = tstate->interp->runtime;
 
 #ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
 struct _gil_runtime_state *gil = &tstate->interp->ceval.gil;


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /