Stackless Python
Will Ware
wware-nospam at world.std.com
Wed Sep 8 11:56:03 EDT 1999
David Oppenheimer (davidopp at megsinet.net) wrote:
: Found this link to a paper by Christian Tismer called Stackless Python.
: I still don't understand everything he's talking about but I found it
: very interesting.
Python normally uses the C stack for some of its house-keeping when it's
running code. Functions, and I believe also blocks within functions, require
data structures called frames to keep track of variable scope and some other
things. These are usually maintained as local variables of eval_code2, a
function in Python/ceval.c. eval_code2 calls itself recursively whenever one
Python function calls another (except for functions which are coded directly
in C), so the eval_code2 call representing the outer function is still on
the C stack, including any frames for the outer function.
What Christian is doing is to set up frame stacks as independent Python
objects, distinct from the C stack. This means that you could interrupt a
Python process and store or study the frozen snapshot. You could continue
the process some time later. You could step many threads, each a few opcodes
at a time, to implement a system of multiple threads. There are probably
other applications that I'm not aware of.
The reason I know this is because I implemented my own multiple-thread package
a few weeks back, having paid insufficient attention when Stackless Python
was first mentioned on the newsgroup. People then pointed out to me that
almost all of what I was doing was already done in Stackless Python.
--
- - - - - - - - - - - - - - - - - - - - - - - -
Resistance is futile. Capacitance is efficacious.
Will Ware email: wware @ world.std.com
More information about the Python-list
mailing list