[Stackless] Micro-threads: runAndContinue(), join()?

Mike Fletcher mfletch at tpresence.com
Mon Oct 23 20:21:17 CEST 2000

I've been getting a number of questions regarding use of micro-threads which
seems to point up some things:

	1) People are used to the threading module, where they start a
thread and the start method immediately returns to the caller with the
thread running in the background (which doesn't happen with micro-threads,
as the scheduler isn't running yet (at least, as far as my understanding

	To give immediate return functionality, my idea is that we could
include a function "runAndContinue()" which encapsulates the rest of the
programme as a continuation and then runs it as a micro-thread alongside the
explicitly created ones.  Unfortunately, the naive implementation:

def runAndContinue():
	'''Scheduler loop that continues running from the current position
	in a micro-thread (i.e. appears to return immediately)'''
	thread = Thread( "<Thread: Main>", None )
	thread.start( task = continuation.caller() )
	print 'scheduler exited normally'
	raise SystemExit(0)

has the annoying trait that when the continuation.caller() is time-sliced it seems to immediately exit the scheduler's loop :o( .  Not sure how one would go about making it work.  Apparently I'm mis-understanding the continuation object here.  Suggestions welcome.

	Can't see auto-starting the scheduler on Thread.start(), as it's not
necessarily true that people want to do so during that method (e.g. the
runAndContinue function above).  That will wind up being an
education/documentation thing I guess.

	2) Related (i.e. you would normally "join" the main thread to the
important threads before the end of the proggy): We don't currently have
"join" functionality (i.e. given a pointer to another micro-thread, wait on
micro-thread exit/complete before continuing in the current micro-thread).
Maybe a more generalised "messageHandler" system would be useful (register
handlers for birth, death, suspension, etc of a thread).  Don't have time to
look into it today, if someone else has an idea, let me know.


 Mike C. Fletcher
 Designer, VR Plumber
Stackless mailing list
Stackless at starship.python.net

More information about the Stackless mailing list