[New-bugs-announce] [issue10220] Make generator state easier to introspect
report at bugs.python.org
Thu Oct 28 14:42:53 CEST 2010
New submission from Nick Coghlan <ncoghlan at gmail.com>:
Generators can be in four different states that may be relevant to framework code making use of them (especially as coroutines). This state is all currently available from Python code, but is rather obscure and could be made readable.
The four states are:
"g.gi_frame is not None and g.gi_frame.f_lasti == -1"
(Frame exists, but no instructions have been executed yet)
(This being true implies other things about the state as well, but this is all you need to check)
Suspended at a yield point:
"g.gi_frame is not None and g.gi_frame.f_lasti != -1 and not g.gi_running"
"g.gi_frame is None"
My API proposal is to add the following to the inspect module:
GEN_CREATED, GEN_RUNNING, GEN_SUSPENDED, GEN_CLOSED = range(4)
if g.gi_frame is None:
if g.gi_frame.f_lasti == -1:
(the lack of underscores in the function name follows the general style of the inspect module)
components: Library (Lib)
stage: needs patch
title: Make generator state easier to introspect
type: feature request
versions: Python 3.2
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce