You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[subinterpreters] Fix pending calls in subinterpreters #84412
Currently, _Py_ThreadCanHandlePendingCalls() only returns true if the current thread is the Python "main thread" (_PyRuntime.main_thread).
_PyRuntime.main_thread is initialized by _PyRuntime_Initialize().
The problem is that a subinterpreter can run a separated thread which may not be the "main thread".
As a consequence, a subinterpreter will not run schedulded pending calls, or it will run them later than it could.
I modified COMPUTE_EVAL_BREAKER() of ceval.c in bpo-40010: now if tstate->interp->ceval.pending.calls_to_do is true, tstate->interp->ceval.eval_breaker is only set to 1 if _Py_ThreadCanHandlePendingCalls() is true.
One option would be to allow any thread to run "pending calls".
Another option is to have one "main thread" per interpreter, rather than having a single "main thread" for all interpreters.
I made pending calls per-interpreter in bpo-39984.
In Python 3.7, main_thread variable came from _PyRutimeState.ceval.pending.main_thread. It was moved into _PyRuntimeState by this change:
bpo-33608: Minor cleanup related to pending calls. (gh-12247)
--
_Py_ThreadCanHandleSignals() doesn't have to change: it must only return true for the main thread of the main interpreter. Currently, it's implemented as:
Activity
vstinner commentedon Apr 8, 2020
Currently, _Py_ThreadCanHandlePendingCalls() only returns true if the current thread is the Python "main thread" (_PyRuntime.main_thread).
_PyRuntime.main_thread is initialized by _PyRuntime_Initialize().
The problem is that a subinterpreter can run a separated thread which may not be the "main thread".
As a consequence, a subinterpreter will not run schedulded pending calls, or it will run them later than it could.
I modified COMPUTE_EVAL_BREAKER() of ceval.c in bpo-40010: now if tstate->interp->ceval.pending.calls_to_do is true, tstate->interp->ceval.eval_breaker is only set to 1 if _Py_ThreadCanHandlePendingCalls() is true.
One option would be to allow any thread to run "pending calls".
Another option is to have one "main thread" per interpreter, rather than having a single "main thread" for all interpreters.
I made pending calls per-interpreter in bpo-39984.
In Python 3.7, main_thread variable came from _PyRutimeState.ceval.pending.main_thread. It was moved into _PyRuntimeState by this change:
commit 5be45a6
Author: Eric Snow <ericsnowcurrently@gmail.com>
Date: Fri Mar 8 22:47:07 2019 -0700
--
_Py_ThreadCanHandleSignals() doesn't have to change: it must only return true for the main thread of the main interpreter. Currently, it's implemented as:
vstinner commentedon Apr 8, 2020
I modified _PyEval_AddPendingCall() to accept interp rather than tstate to fix bpo-40082:
New changeset b54a99d by Victor Stinner in branch 'master':
bpo-40082: trip_signal() uses the main interpreter (GH-19441)
b54a99d
[-]Fix pending calls in subinterpreters[/-][+][subinterpreters] Fix pending calls in subinterpreters[/+][-]Fix pending calls in subinterpreters[/-][+][subinterpreters] Fix pending calls in subinterpreters[/+]vstinner commentedon Nov 3, 2022
I don't have the bandwidth to work on this issue, so I just close it.