yield: implementation details and other technica
David Mertz, Ph.D.
mertz at gnosis.cx
Tue Nov 19 20:44:21 EST 2002
I have a technical problem for which grabbing the context of a
generator and *throwing* it up the stack would be preferable to the
current implementation... What I want is a giant coroutine between
a bunch of objects and a master scheduler that I control....For one,
certain high level methods are called that imply a yield in a higher
context.
"Raymond Hettinger" <vze4rx4y at verizon.net> wrote previously:
|Joe, try looking at:
|http://gnosis.cx/publish/programming/charming_python_b7.txt
|The article shows how to use generators with a master scheduler. His
|example shows how to implement co-routines, but it is general purpose.
|Used this way, the scheduler has the ability to resume any process,
|in effect deciding the current continuation.
The article Raymond suggest is indeed probably the most on topic. It
also follows on a related one. The HTML versions of both are at:
http://gnosis.cx/publish/programming/charming_python_b5.html
http://gnosis.cx/publish/programming/charming_python_b7.html
Moreover, for some more fleshed out examples of scheduling generators,
take a look at the SimPy project. The authors of that use a bit of the
framework I suggested in those articles, but in a much more fleshed out
form. The also handle some data passing in a nice way. But it's not
hard to yield some "cargo" along with a state target, in any case.
One thing I regret in my first article on this is that I used string
names for targets rather than the callable objects themselves. I think
the latter article fixed that, and I believe SimPy does to.
Generators are even more cool that you might think at first brush.
Yours, David...
--
mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i
gnosis _/_/ Postmodern Enterprises _/_/ s r
.cx _/_/ MAKERS OF CHAOS.... _/_/ i u
_/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s
More information about the Python-list
mailing list