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/ef4ec6ed12d6c6200a85068f60483723298b6ff4/Python/ceval.c#L943>
).

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/ef4ec6ed12d6c6200a85068f60483723298b6ff4/Python/ceval.c#L1000>).
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
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/6ZAY27URSSZQTVOJQVND46M4XEL46OWN/

Reply via email to