Question on handling of per-thread async exception with global pending.async_exc flag

Hi, I am trying to understand the way that async exceptions are handled between _PyEval_EvalFrameDefault (in ceval.c) and PyThreadState_SetAsyncExc (pystate.c). In ceval.c, the eval loop determines whether to check for async exception for the current thread based on the global _PyRuntime.ceval.eval_breaker, which takes the global _PyRuntime.ceval.pending.async_exc as a factor ( source <https://github.com/python/cpython/blob/ef4ec6ed12d6c6200a85068f60483723298b6...> ). It feels to me that this implementation will result in missing breaks if async exceptions are set on multiple threads - because _PyRuntime.ceval.eval_breaker and _PyRuntime.ceval.pending.async_exc are shared across multiple threads. After breaking in the first thread and handling its async exception, the two flags are cleared in UNSIGNAL_ASYNC_EXC (source <https://github.com/python/cpython/blob/ef4ec6ed12d6c6200a85068f60483723298b6...>). As a result, the second thread will not get the eval breaker. The other flags, like signals and pending calls, do not have this issue because they are only handled on the main thread, which effectively makes the shared flags exclusive for main thread consumption. However, async exception handling is different in this regards. Is this reading correct? Thanks, Xintong
participants (1)
-
Xintong Zhou