GeezerVison is showing github.com — gh-120321: Add gi_state, cr_state, and ag_state attributes by colesbury · Pull Request #144409 · python/cpython
Conversation
colesbury
commented
Feb 2, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
📚 Documentation preview 📚: https://cpython-previews--144409.org.readthedocs.build/
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
|
| | | one of ``GEN_CREATED``, |
|
|
|
| | | ``GEN_RUNNING``, |
|
|
|
| | | ``GEN_SUSPENDED``, or |
|
|
|
| | | ``GEN_CLOSED`` |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a .. versionchanged:: next markup at the end of the table to mention that gi_state, ag_state, cr_state are added in Python 3.15.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
colesbury reacted with thumbs up emoji
|
|
FRAME_SUSPENDED_YIELD_FROM = -2,
|
|
|
FRAME_SUSPENDED_YIELD_FROM_LOCKED = -1,
|
|
|
FRAME_EXECUTING = 0,
|
|
|
FRAME_COMPLETED = 1,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to mention FRAME_COMPLETED removal in the commit message. I'm fine with the removal, the constant was only used in one place: in FRAME_STATE_FINISHED().
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've edited the PR description and will use that when squash + merging.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
vstinner reacted with thumbs up emoji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.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.Add this suggestion to a batch that can be applied as a single commit.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.Suggestion cannot be applied right now. Please check back later.
|