[Stackless] Newbie questions

Christian Tismer tismer at tismer.com
Sun Feb 16 01:39:21 CET 2003

Konrad Hinsen wrote:
> I have been following Stackless development from a distance for a while, out 
> of pure curiosity, but now I am more directly interested, so I downloaded a 
> copy and subscribed to this list.

Fascinating to have *you* in this. I'm pretty sure
you will force me to implement MPI and other stuff, soon.

> To prove my complete ignorance, and to show 
> my laziness (I could of course get all the answers from the code), I'll start 
> with some questions:
> 1) How does Stackless cooperate with C extension modules? Are there any
>     precautions that need to be taken?

Yes. With 2.0, there is an issue, which didn't exist in 1.0,
because it wasn't able to switch extensions at all.
You can switch between any two tasklets, regardless in which
extension that happens. This especially might give you a
problem in callbacks. This is also the reason why 2.0 refuses
to use pre-emptive multitasking, since a switch could happen
inside of an extension that cannot stand it.

So what about the problem?
The problem is that SLP 2.0 does not switch stacks, but it
*moves* stacks. DUring a switch, the stack content is packed
into a tructure and replaced by a different activation record.
This has advantages and disadvantages. An advantage is that
tasklets have very small size, usually, since I don't have
to reserve lots of stack space for every tasklet. There is
only one real stack.
Disadvanteageous is of course that this costs a bit more time
than stack switching, *and* that pseudo-global data which is
sitting on the stack, suddenly becomes unavailable.
One problem for instance was tkinter with callbacks. Tcl does
(ab)use the C stack for global state. I asked them to change this,
and as I heared, it is changed in the last versions.

In other words: If your extension does not call back into
Python, or if it does, but there are no switches intended,
you have no problem.
But if you switch from an extension which relies on variables
being alive on the stack, you got a problem.

> 2) What are the semantics of channel transfers? Are the received objects
>     identical to the sent one, or are they shallow copies, deep copies, ...?

The sent objects of channels are identical to the
sent ones. This might change, since I want to use
the channel protocol over different machines as well,
but for now, this is implemented in the cheapest possible way.

> BTW, the two applications that got me interested in Stackless are GUI issues 
> (having a "GUI thread" and a "compute thread" even on platforms that don't 
> support pthreads) and parallel computing. The latter may seem strange given 
> the inherently serial nature of Stackless, but it isn't ;-) More later, if 
> anyone is interested.

Very much interested!
I'm using the same paradigm in a commercial application which
uses Stackless, PIL, wxPython and some more. I could have used
real threads, but Stackless was very convenient, and I have
very good control over my tiny processes.
Will show that app on PyCon, together with the EVE online game,
which is the largest Stackless application known today.

all the best -- 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

More information about the Stackless mailing list