[Stackless] Can Someone explain...

Vesselin Peev vesselinpeev at hotmail.com
Sun Dec 29 13:12:47 CET 2002

Perhaps it could be useful to elaborate on why one should choose/not
choose Stackless when there are generators available in Python? For
example, one game company (the one that wrote the Python debugger HAP)
reviewed Stackless since it needed the described pseudo multi-tasking
functionality, but in the end chose to use "generators" from ordinary
Python that were only introduced in a recent version. One of their
reasons against Stackless was that it needs a non-portable fix to the
original Python code done by hand.
Since this is not a problem for the vast majority of people, I think
people would be interested in other pro's/con's of using Stackless and
what it implements and allows different from the generator technique

-----Original Message-----
From: stackless-admin at tismer.com [mailto:stackless-admin at tismer.com] On
Behalf Of Christian Tismer
Sent: Sunday, December 29, 2002 5:00 AM
To: Daniel C Landon Jr
Cc: stackless at tismer.com
Subject: Re: [Stackless] Can Someone explain...

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

Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.434 / Virus Database: 243 - Release Date: 12/25/2002

Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.434 / Virus Database: 243 - Release Date: 12/25/2002

More information about the Stackless mailing list