Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-120321: Add gi_state, cr_state, and ag_state attributes#144409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
colesbury merged 6 commits intopython:mainfromcolesbury:gh-120321-gen-state
Feb 3, 2026

Conversation

@colesbury
Copy link
Contributor

@colesburycolesbury commentedFeb 2, 2026
edited
Loading

Addgi_state,cr_state, andag_state attributes to generators, coroutines, and async generators respectively. These attributes return the current state as a string (e.g.,GEN_RUNNING,CORO_SUSPENDED).

Theinspect.getgeneratorstate(),inspect.getcoroutinestate(), andinspect.getasyncgenstate() functions now return these attributes directly.

This is in preparation for makinggi_frame thread-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 unusedFRAME_COMPLETED state and renumbers the frame state enum to start at 0 instead of -1.


📚 Documentation preview 📚:https://cpython-previews--144409.org.readthedocs.build/

Add `gi_state`, `cr_state`, and `ag_state` attributes to generators,coroutines, and async generators respectively. These attributes returnthe current state as a string (e.g., `GEN_RUNNING`, `CORO_SUSPENDED`).The `inspect.getgeneratorstate()`, `inspect.getcoroutinestate()`, and`inspect.getasyncgenstate()` functions now return these attributesdirectly.This is in preparation for making `gi_frame` thread-safe, which mayinvolve stop-the-world synchronization. The new state attributes avoidpotential performance cliffs in `inspect.getgeneratorstate()` andsimilar functions by not requiring frame access.
| | | one of ``GEN_CREATED``, |
| | | ``GEN_RUNNING``, |
| | | ``GEN_SUSPENDED``, or |
| | | ``GEN_CLOSED`` |
Copy link
Member

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.

colesbury reacted with thumbs up emoji
FRAME_SUSPENDED_YIELD_FROM = -2,
FRAME_SUSPENDED_YIELD_FROM_LOCKED = -1,
FRAME_EXECUTING = 0,
FRAME_COMPLETED = 1,
Copy link
Member

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().

Copy link
ContributorAuthor

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.

Copy link
Contributor

@kumaraditya303kumaraditya303 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM

@colesburycolesbury merged commit7e2c9bd intopython:mainFeb 3, 2026
47 checks passed
@colesburycolesbury deleted the gh-120321-gen-state branchFebruary 3, 2026 18:06
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@vstinnervstinnervstinner left review comments

@kumaraditya303kumaraditya303kumaraditya303 approved these changes

@AA-TurnerAA-TurnerAwaiting requested review from AA-TurnerAA-Turner is a code owner

@ericsnowcurrentlyericsnowcurrentlyAwaiting requested review from ericsnowcurrentlyericsnowcurrently is a code owner

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@colesbury@vstinner@kumaraditya303

[8]ページ先頭

©2009-2026 Movatter.jp