[Stackless] Stackless Q

Richard Tew richard.m.tew at gmail.com
Wed Feb 21 11:24:56 CET 2007

On 2/21/07, mobiledreamers at gmail.com <mobiledreamers at gmail.com> wrote:
> Dear Richard
> Can you give me as simple example or basic boiler plate code for stackless,
> so i could start off

There are two approaches you can take.

The first is to treat the scheduler as something which returns when your
code has finished.  This is just a matter of making sure that there
are always running tasklets in the scheduler.  It is worth knowing that
tasklets which are blocked on channels are not running, so if all your
tasklets are blocked on channels (perhaps wrapping asychronous calls
to sockets) the scheduler will have nothing to run and will exit.  And if
you are using it running as the mechanism to keep the Python runtime
and therefore your application from exiting, then your application will
exit prematurely.  This approach is just running the scheduler with a
call to:


The second is to treat the scheduler as something which just runs the
tasklets once and to rerun it as long as you want your application to
be running.  This involves making sure that nothing uses the function
stackless.schedule and instead that a function like in the BeNice
idiom is used.. see here:


In either case it is useful to bring in something like the Sleep idiom.

I am always more than happy to expand the range of stackless examples
and an example of both these approaches would be of benefit to Stackless.

You can see use of Stackless with tasklets in the examples.  Given the
restrictions which each approach has, creating a tasklet is the same
either way, it just comes down to being aware of how you are using them.


Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list