[Stackless] Can Someone explain...

Christian Tismer tismer at tismer.com
Sun Dec 29 03:59:53 CET 2002

Daniel C Landon Jr wrote:
> All,
> I am just learning PYTHON so I do not understand what it means to not 
> use the C Stack. What kind of advantages not using the C Stack would 
> give me.

This is basically simple and will go into the FAQ, as
soon as it comes to existence.

Python is fine. As long as you are just calling
every function after the other, as usual. And you
return from every functions as usual. Python is fine.

After a while, there might evolve the wish to change
order of execution. Not saying that you would like to
avoid returning to the function that called you, while
even this might be possible -- no, just the wish to
run a couple of functions in parallel.

Parallel? You might argue that there is no true parallism
on a single processor, and that you already can use
parallel paths of execution by means of the threading

You are right. Everything is possible by means of threads.

But threads are not cheap concerning memory, and sometimes
not too cheap by measures of switching time. This is very
system dependant.
The typical size of an OS thread is around a megabyte.
You can get it smaller. WIth a speciual Linux version,
you can get 100.000 threads out of a Gigabyte. But this
is the very extreme. Usually, even several hundred threads
is at the limits of your machine.

So how is this related to C stacks?
Well, Python is a recursive interpreter.
Everytime you call a function, there is a new
recursive interpreter call, which uses space
on the C stack. And it is exactly that call
that makes it hard to just switch to another
Python function.
Threads enable this by switching to a different
C stack, by using a diferent thread.

Stackless does this by avoiding recursions at all,
or by moving tiny stack slices around. Don't bother
*how* this works, it just works, and it is by a factor
of 100 to 1000 more effective than using threads.

In Stackless, you can create as many of tiny tasklet
objects as you like. You can let them run in parallel,
using an auto-scheduling scheme or doing your own
tasklet switchig, and you can let them control themselves
by communicating over channels, which are the simplest
possible flow control construct I can imagince.
As a Python programmer, you can have as much control
over your system as you like to have.

We will provide a couple of example applications,
soon. Simple things with just a few tasklets for
a few simple jobs to perform. And there will be
examples with thousands or millions of tasklets,
doing massive simulations of parallel systems.

Anyway, all of this is only possible, if it is cheap
to switch between running Python functions. And this
is only cheap if there is no or almost no C stack
involved. All of Stackless can run in a single OS
thread, on a single C stack.

This is all without *any* change to Python's semantics.
Stackless is no different from Python. Everything
will run, and you can use it instead of the regular
Python without changing your programs.

Stackless just gives you some more, it adds a little
bit of functionality. But this can be so much in the
hand of people who know how to use it. A whole
new world of applications becomes possible, things
that I've never thought of before.

Hmmm... please let me know where the deficiencies
   of this text are.

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