gh-120321: Add gi_state, cr_state, and ag_state attributes by colesbury · Pull Request #144409 · python/cpython
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.
thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request
…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