Python microthreads

Will Ware wware-nospam at world.std.com
Tue Aug 3 10:31:08 EDT 1999


Dirk-Ulrich Heise (hei at adtranzsig.de) wrote:
: Did you build it on top of Christian Tismers
: Stackless Python, or is it a different kind of
: modification to the VM?

I haven't looked at Stackless Python, but it sounds like an unrelated
thing. As I recall, Stackless Python uses the C stack for everything
whereas normally Python has a piece of stack in each frame object.
It can do this because the compiler is smart enough to figure out
exactly how much stack will be needed for any function call. So
frameobjects have a field called f_valuestack which maintains the
arguments and local variables for that function.

What I did was to keep the frameobject exactly as it is in normal
Python, but invent a thread object with a stack for frameobjects,
and a couple more stacks for stack pointers and program counters.
Additionally, I modified the bytecode interpreter (eval_code2, in
ceval.c) so that it runs for a specified number of opcodes and
then stops, leaving the entire environment intact. This lets you
rotate thru several threads, executing each for a few opcodes, so
it looks like the threads are running simultaneously.
-- 
 - - - - - - - - - - - - - - - - - - - - - - - -
Resistance is futile. Capacitance is efficacious.
Will Ware	email:    wware @ world.std.com




More information about the Python-list mailing list