{{ message }}
gh-120321: Add gi_state, cr_state, and ag_state attributes#144409
Merged
colesbury merged 6 commits intoFeb 3, 2026
Merged
Conversation
Add `gi_state`, `cr_state`, and `ag_state` attributes to generators, coroutines, and async generators respectively. These attributes return the current state as a string (e.g., `GEN_RUNNING`, `CORO_SUSPENDED`). The `inspect.getgeneratorstate()`, `inspect.getcoroutinestate()`, and `inspect.getasyncgenstate()` functions now return these attributes directly. This is in preparation for making `gi_frame` thread-safe, which may involve stop-the-world synchronization. The new state attributes avoid potential performance cliffs in `inspect.getgeneratorstate()` and similar functions by not requiring frame access.
vstinner
reviewed
Feb 3, 2026
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
kumaraditya303
approved these changes
Feb 3, 2026
kumaraditya303
left a comment
Contributor
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
Hide details
View details
colesbury
merged commit
7e2c9bd
into
python:main
Feb 3, 2026
47 checks passed
thunder-coding
pushed a commit
to thunder-coding/cpython
that referenced
this pull request
Feb 15, 2026
…hongh-144409) Add `gi_state`, `cr_state`, and `ag_state` attributes to generators, coroutines, and async generators respectively. These attributes return the current state as a string (e.g., `GEN_RUNNING`, `CORO_SUSPENDED`). The `inspect.getgeneratorstate()`, `inspect.getcoroutinestate()`, and `inspect.getasyncgenstate()` functions now return these attributes directly. This is in preparation for making `gi_frame` thread-safe, which may involve stop-the-world synchronization. The new state attributes avoid potential performance cliffs in `inspect.getgeneratorstate()` and similar functions by not requiring frame access. Also removes unused `FRAME_COMPLETED` state and renumbers the frame state enum to start at 0 instead of -1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.
Add
gi_state,cr_state, andag_stateattributes to generators, coroutines, and async generators respectively. These attributes return the current state as a string (e.g.,GEN_RUNNING,CORO_SUSPENDED).The
inspect.getgeneratorstate(),inspect.getcoroutinestate(), andinspect.getasyncgenstate()functions now return these attributes directly.This is in preparation for making
gi_framethread-safe, which may involve stop-the-world synchronization. The new state attributes avoid potential performance cliffs ininspect.getgeneratorstate()and similar functions by not requiring frame access.Also removes unused
FRAME_COMPLETEDstate and renumbers the frame state enum to start at 0 instead of -1.📚 Documentation preview 📚: https://cpython-previews--144409.org.readthedocs.build/