Uh oh!
There was an error while loading. Please reload this page.
gh-120321: Add gi_state, cr_state, and ag_state attributes - #144409
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.
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.
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.
| FRAME_SUSPENDED_YIELD_FROM = -2, | ||
| FRAME_SUSPENDED_YIELD_FROM_LOCKED = -1, | ||
| FRAME_EXECUTING = 0, | ||
| FRAME_COMPLETED = 1, |
There was a problem hiding this comment.
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().
There was a problem hiding this comment.
I've edited the PR description and will use that when squash + merging.
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Uh oh!
There was an error while loading. Please reload this page.
…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.
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/