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
Find a way to handle branch events in async for #128534
When instrumenting regular for loops, we instrument the FOR_ITER instruction as the LEFT branch and the POP_ITER instruction as the RIGHT branch.
This doesn't work for async for as it uses exceptions to exit the loop.
Raising an exception is the documented behavior for exiting a [async] generator, so we will still need to generate an event for the exception being raised, much as we do in INSTRUMENTED_END_FOR as well as the BRANCH events.
One way to instrument this would be to add a NOT_TAKEN after the END_SEND or instrument the END_SEND for the LEFT branch, For the RIGHT branch we could instrument END_ASYNC_FOR.
This shouldn't prevent future specialization of async for as that would require splitting END_ASYNC_FOR into two instructions. We would then instrument the second.
Activity
markshannon commentedon Jan 6, 2025
The bytecode for
is
One way to instrument this would be to add a
NOT_TAKENafter theEND_SENDor instrument theEND_SENDfor theLEFTbranch, For theRIGHTbranch we could instrumentEND_ASYNC_FOR.This shouldn't prevent future specialization of
async foras that would require splittingEND_ASYNC_FORinto two instructions. We would then instrument the second.GH-128534: Instrument branches for `async for` loops. (GH-130569)
markshannon commentedon Mar 3, 2025
We still need to add these new branches to
co_branches()GH-128534: Fix behavior of branch monitoring for `async for` (GH-130847)