Python microthreads

Markus Stenberg mstenber at cc.Helsinki.FI
Tue Aug 3 17:54:30 CEST 1999

wware-nospam at (Will Ware) writes:
> Dirk-Ulrich Heise (hei at 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.

No.. Stackless python does _not_ use C stack. Normal python does. AFAIK,
that's what the stackless stands for (purely frame objects and such).

> 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.

Sounds like something you could do with Stackless Python, or on top of,
fairly easily. 



	"If you want to travel around the world and be invited to speak at
	a lot of different places, just write a Unix operating system."
		-- Linus Torvalds

More information about the Python-list mailing list