yield: implementation details and other technica

Courageous jkraska at san.rr.com
Tue Nov 19 20:52:39 EST 2002


>The gist of the appoach is that each process gets initiated through the
>master scheduler which is then responsible for making the g.next() calls
>when appropriate.  Whenever the generator yields, it returns control back to
>the scheduler and freezes its current state.

This response was helpful from an educational point of view, but alas
isn't what I want. Consumers of my API must call yield. "Yield" clashes
with the domain language I'm trying to construct in my simuylator. It
looks like I'm stuck with Stackless for Python 2.0.X for the time being.

I basically need some general purpose mechanism whereby, no matter
how deeply nested, a call to yield "throws" an execution frame up
to a point where it can be "caught" and then scheduled. I.O.W., nested
methods/functions need to be able to yield their parent's execution
frames. This is, AFAICT, not possible with the current implementation
of yield.

I want this to work:

def g():

	f()

def f():

	yield None

x = g()
g.next()

I understand that it doesn't work, and possibly won't or can't be made to
work as is. I require a context in which it does, however; hence my current
use of Stackless. My main complaint with Stackless is simply that future
versions of Python are not supported (and that the current Stackless lost
old functionality, and is in flux).

C//




More information about the Python-list mailing list