diff options
author | Victor Stinner <vstinner@python.org> | 2020-03-19 02:41:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-19 02:41:21 +0100 |
commit | 50e6e991781db761c496561a995541ca8d83ff87 (patch) | |
tree | 3380890960438581d8262ad24e2c8b346d664c87 /Python/pylifecycle.c | |
parent | 3cde88439d542ed8ca6395acc8dfffd174ecca18 (diff) | |
download | cpython-git-50e6e991781db761c496561a995541ca8d83ff87.tar.gz |
bpo-39984: Move pending calls to PyInterpreterState (GH-19066)
If Py_AddPendingCall() is called in a subinterpreter, the function is
now scheduled to be called from the subinterpreter, rather than being
called from the main interpreter.
Each subinterpreter now has its own list of scheduled calls.
* Move pending and eval_breaker fields from _PyRuntimeState.ceval
to PyInterpreterState.ceval.
* new_interpreter() now calls _PyEval_InitThreads() to create
pending calls lock.
* Fix Py_AddPendingCall() for subinterpreters. It now calls
_PyThreadState_GET() which works in a subinterpreter if the
caller holds the GIL, and only falls back on
PyGILState_GetThisThreadState() if _PyThreadState_GET()
returns NULL.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index da2bb37af5..b7019e3bb6 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -556,7 +556,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime, return status; } - /* Create the GIL */ + /* Create the GIL and the pending calls lock */ status = _PyEval_InitThreads(tstate); if (_PyStatus_EXCEPTION(status)) { return status; @@ -1581,6 +1581,12 @@ new_interpreter(PyThreadState **tstate_p) goto error; } + /* Create the pending calls lock */ + status = _PyEval_InitThreads(tstate); + if (_PyStatus_EXCEPTION(status)) { + return status; + } + *tstate_p = tstate; return _PyStatus_OK(); |