Stackless Python and Python 2.x
Skip Montanaro
skip at pobox.com
Wed Sep 5 10:27:27 EDT 2001
Michael> How does the Python interpreter maintain the state of a
Michael> generator during calls to yield? Evidently the entire state
Michael> has to be restored from wherever it's being kept and plonked
Michael> back onto the current stack.
I believe simple generators can only yield back to their caller, so all
that's necessary (in my simple-minded view of things) is to retain a
reference to the stack frame when yield is executed and not reinitialize the
stack frame the next time the generator is called.
Michael> Perhaps this is a slightly stupid question, but it's more
Michael> interesting than the other "What part of ... do you not
Michael> understand?" stuff.
Agreed.
--
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/
More information about the Python-list
mailing list