Stackless Python and Python 2.x
gmcm at hypernet.com
Sun Sep 2 14:06:48 CEST 2001
>> Wasn't a big part of the generator addition that it supplies a
>> simpler-to-understand solution to the majority of continuations
> I expect that if you dug into all the applications using Stackless,
> you'd find that the majority of them rely on full-blown coroutines or
> microthreads. It's unclear how far PEP 255's "Simple Generators" can
> be pushed towards those specific ends.
Alas, not far enough. I've used Stackless a number of times to
turn state machines inside out (where the number of events is
smallish but the state stuff is complex, this is a wonderful
simplification). Generally this means that there's a whole
set of frames hanging around when I "yield".
To the non-coroutine aware, this is better explained from a
thread POV - I have a bunch of "threads" that are dispatched
when an event is received, and only swap out when they want to.
The advantages over real threads are enormous:
- system level locks never needed
- user level locks rarely needed
The only downside is relatively minor - I have to make
sure that one "thread" doesn't monopolize the CPU.
> Neil Schemenauer discovered that it was possible to code the
> "traditional" coroutine examples using simple generators instead...
Yah, well your "traditional" thread example prints the numbers
1 through 10 twice in some interleaving...
More information about the Python-list