[Stackless] Figuring out stackless for use in Twisted

Christian Tismer tismer at tismer.com
Mon Jul 28 13:51:08 CEST 2003


Christopher Armstrong wrote:

> So, I'm trying to write a Stackless Reactor for Twisted.

That sounds phantastic.

> I'm pretty clueless about Stackless, now, though. Is there any
> relevant documentation other than what's in the docstrings of the
> stackless module and the classes it contains?

No. I'm building a Wiki, but due to recent financial
problems, I didn't finish what I started 2 weeks ago.

> Right now I'm trying to figure out what exactly `become' does. The
> docs say that it captures the current frame in the tasklet. I can
> somewhat understand this, but I'm not sure what happens to the code
> calling the function (named, say, FOO) that calls t.become(). Does it
> just block until `t' switches context back? And: Does blocking on a
> channel.receive automatically switch back to the main tasklet? I
> assume that just means that the call to FOO will return?

If you call t.become(), the current running frame is
ripped off the frame stack and wrapped by a new
tasklet object. become() then returns to the caller
(so the active tasklet stays active) and returns the
new tasklet as a value, unless you provide a different one.

In contrast, if you call t.capture(), the same happens,
but the newly created tasklet continues to execute,
leaving the old tasklet behind in the list of runnables.

When the original tasklet is resumed depends on how
many other tasklets are in the runnables queue.
This is no blocking, it is just scheduling order.

The real blocking is in the channels. If channel.receive
does not have a waiting sender, the receiver gets blocked,
that is, it is ripped off the runables queue and put
into a chain of the channel.
After such blocking, the next available tasklet from the
runnables list is activated, reagrdless whether this
is main or not.
Main does not have any special role but this:
Every uncaptured exceptions are handled by main.
Even if main happens to be blocked, it is activated
as the error handler.
Typically, main will be inactive while running all
other tasklets by stackless.run().

...

> Oh, and before I forget: I just built stackless from CVS today, and
> when I try to help(stackless) with my brand new build this is what I
> get::
> 
> 
>>>>help(stackless)
> 
> Traceback (most recent call last):
...

> Just an annoying little thing. I've just been reading the docstrings
> by browsing the source (and help(stackless.tasklet) still works). :-)

Oops, yes this is right. Since a while, I'm storing
special values in the dict of the frame type, under
an integer key. Didn't realize this.
So probably I have to change this? Is it "forbidden"
to have non-string keys in type dicts?

cheers - chris

-- 
Christian Tismer             :^)   <mailto:tismer at tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/

_______________________________________________
Stackless mailing list
Stackless at www.tismer.com
http://www.tismer.com/mailman/listinfo/stackless




More information about the Stackless mailing list