GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@colesbury colesbury commented Feb 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

  • Issue: SIGSEGV with generators in free-threaded build #120321

📚 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.

All reactions
@colesbury
pythongh-120321: Add gi_state, cr_state, and ag_state attributes
f3335d3
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.
@colesbury colesbury added the topic-free-threading label Feb 2, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Feb 2, 2026
SIGSEGV with generators in free-threaded build #120321
Closed
kumaraditya303
kumaraditya303 reviewed Feb 3, 2026
View reviewed changes
Comment thread Objects/genobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Feb 3, 2026
View reviewed changes
Comment thread Objects/genobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Feb 3, 2026
View reviewed changes
Comment thread Objects/genobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner reviewed Feb 3, 2026
View reviewed changes
Comment thread Doc/library/inspect.rst
| | | one of ``GEN_CREATED``, |
| | | ``GEN_RUNNING``, |
| | | ``GEN_SUSPENDED``, or |
| | | ``GEN_CLOSED`` |

@vstinner vstinner Feb 3, 2026

Copy link
Copy Markdown
Member

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
All reactions
  • 👍 1 reaction
Comment thread Include/internal/pycore_frame.h
FRAME_SUSPENDED_YIELD_FROM = -2,
FRAME_SUSPENDED_YIELD_FROM_LOCKED = -1,
FRAME_EXECUTING = 0,
FRAME_COMPLETED = 1,

@vstinner vstinner Feb 3, 2026

Copy link
Copy Markdown
Member

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.

All reactions

@colesbury colesbury Feb 3, 2026

Copy link
Copy Markdown
Contributor Author

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
All reactions
  • 👍 1 reaction
@colesbury
colesbury marked this pull request as ready for review February 3, 2026 15:18
@colesbury
colesbury requested review from AA-Turner, ericsnowcurrently and markshannon as code owners February 3, 2026 15:18
@bedevere-app bedevere-app Bot added the awaiting core review label Feb 3, 2026
colesbury and others added 3 commits February 3, 2026 10:18
@colesbury @kumaraditya303
Apply suggestions from code review
86c06fa
Co-authored-by: Kumar Aditya <[email protected]>
@colesbury
Add versionchanged markup
71a9532
@colesbury
Fix NEWS markup
be25720
kumaraditya303
kumaraditya303 approved these changes Feb 3, 2026
View reviewed changes

@kumaraditya303 kumaraditya303 left a comment

Copy link
Copy Markdown
Contributor

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.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Feb 3, 2026
colesbury added 2 commits February 3, 2026 10:59
@colesbury
Regen test_frozenmain.h
59a219b
@colesbury
Add state_strings arrays to c-globals ignore list
b7fb695
@colesbury
colesbury merged commit 7e2c9bd into python:main Feb 3, 2026
47 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@colesbury
colesbury deleted the gh-120321-gen-state branch February 3, 2026 18:06
@bedevere-app bedevere-app Bot removed the awaiting merge label Feb 3, 2026
thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
@colesbury @thunder-coding
pythongh-120321: Add gi_state, cr_state, and ag_state attributes (pyt…
802f326
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner left review comments
@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic-free-threading

Projects

None yet

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.

3 participants

@colesbury @vstinner @kumaraditya303
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.