Nick Coghlan <ncogh...@gmail.com> added the comment: So something like:
GEN_CREATED, GEN_ACTIVE, GEN_CLOSED = range(3) def getgeneratorstate(g): """Get current state of a generator-iterator. Possible states are: GEN_CREATED: Created, waiting to start execution GEN_ACTIVE: Currently being executed (or suspended at yield) GEN_CLOSED: Execution has completed Use g.gi_running to determine if an active generator is running or is suspended at a yield expression. """ if g.gi_frame is None: return GEN_CLOSED if g.gi_frame.f_lasti == -1: return GEN_CREATED return GEN_ACTIVE Having 4 separate states actually makes the documentation a little easier to write: def getgeneratorstate(g): """Get current state of a generator-iterator. Possible states are: GEN_CREATED: Waiting to start execution GEN_RUNNING: Currently being executed by the interpreter GEN_SUSPENDED: Currently suspended at a yield expression GEN_CLOSED: Execution has completed """ Checking if the generator is active is then just a matter of checking "gen_state in (GEN_RUNNING, GEN_SUSPENDED)". ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue10220> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com