[Stackless] Questions on the Evolution of Stackless

Christopher Armstrong radix at twistedmatrix.com
Tue Feb 26 17:36:54 CET 2008


On Tue, Feb 26, 2008 at 10:47 AM, Andrew Francis <andrewfr_ice at yahoo.com> wrote:
>  3) I see greenlets, generators, tasklets and now
>  eventlets - all different types of coroutines. In
>  Twisted, I see inlineCallbacks (based on generators).
>
>  Silly question, besides the programming interface,
>  what really is the difference between a
>  tasklet/channel and generator? Tasklets and channels
>  seem more general purpose and powerful.

Generators are not coroutines and cannot be used to implement
coroutines. Unfortunately the Python community (starting with the PEP
for generators in 2.5) has decided to use the word "coroutine" to
describe what they can do, so probably it's impossible to get away
from that misnomer at this point.

The main difference is that you cannot switch between arbitrary
generators at arbitrary stack levels. This means that every frame in
the stack has to have knowledge of potential context switches.
inlineCallbacks is an example of this; every frame in the stack needs
to know to 'yield' the deferred in order to wait for its result. With
real coroutines (greenlets, tasklets) you can have arbitrary calling
code that just calls a function in a normal, synchronous-looking way,
and have the called function switch without the caller's knowledge.
This means it's easier for bad stuff to happen, but it's also more
flexible.

-- 
Christopher Armstrong
International Man of Twistery
http://radix.twistedmatrix.com/
http://twistedmatrix.com/
http://canonical.com/




More information about the Stackless mailing list