bpo-40010: Optimize pending calls in multithreaded applications by vstinner · Pull Request #19091 · python/cpython

If a thread different than the main thread schedules a pending call
(Py_AddPendingCall()), the bytecode evaluation loop is no longer
interrupted at each bytecode instruction to check for pending calls
which cannot be executed. Only the main thread can execute pending
calls.

Previously, the bytecode evaluation loop was interrupted at each
instruction until the main thread executes pending calls.

  • Add _Py_ThreadCanHandlePendingCalls() function.
  • SIGNAL_PENDING_CALLS() now only sets eval_breaker to 1 if the
    current thread can execute pending calls. Only the main thread can
    execute pending calls.

https://bugs.python.org/issue40010