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
Commit d3251e7
Browse filesBrowse the repository at this point in the historyBrowse files
gh-161170: Lazily materialize coroutine objects for awaited calls
`await f()` on an `async def` no longer allocates a coroutine object
unless the body actually suspends.
Python-function CALL paths with the awaited flag mark the new frame of
a coroutine function (_MAYBE_LAZY_CORO). RETURN_GENERATOR then keeps
running the body in that frame, with its own exception state item on
the data stack. The body reports how it ended through the slot below
the awaited call, and END_AWAITED_CALL acts on it:
- the body returned: clear_thread_frame() stores a tagged int, and
END_AWAITED_CALL skips the SEND loop;
- the body suspended: YIELD_VALUE leaves the frame and its exception
state on the data stack and stores the frame. END_AWAITED_CALL
creates the coroutine, moves both into it and jumps to the
YIELD_VALUE of the SEND loop with (coroutine, NULL, value), as SEND
would have left them;
- the body raised: the exception is raised from END_AWAITED_CALL,
which has the location of the await.
END_AWAITED_CALL is never instrumented, so nothing runs between the
body's suspension and the creation of its coroutine. It reports the
STOP_ITERATION event of the END_SEND it skips.
Calls from C, instrumented calls, coroutine origin tracking, JIT trace
recording and tier 2 keep creating the coroutine eagerly.
frame.f_generator and PyFrame_GetGenerator() return None/NULL for such
a coroutine until it first suspends; asyncio.graph classifies frames
by co_flags instead.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0 commit comments