MicroThread (uthread) queue

Mike Fletcher mfletch at tpresence.com
Sun Sep 17 18:59:03 CEST 2000

Hmm, question is kinda vague, but here's a pattern that might work...

def appMainloop():
	for x in numberOfWantedProcessingThreads:
		uthread9.new( queueProcessingThread, queue )

uthread9.new( appMainLoop )

#Note: you don't have to start all of your threads at 
#the same time, any micro-thread can create more 
#micro-threads.  Cute-lil tribbles...

Uthread9 will still block until all the threads have finished, but since
your main thread of execution is a uthread as well, you want that in this
case.  If you need, for instance, multiple threads (but not all) to finish
before you continue processing in a particular thread, check out the
Synchronizer object, passing a Synchronizer to each of the micro-threads
that needs to wait (they call it when they're done), and calling it in your
"mainloop" as well, so that when the last required thread is ready all of
the threads are released (most of them just exiting immediately, but the
mainloop continuing on).

Just realised we don't have a "join" mechanism... might be a nice addition I
suppose.  At the moment I've got other problems with micro-threads so I'm
not going to be doing that, feel free to try it :o) .


-----Original Message-----
From: Chris Armstrong [mailto:punck at PenguinMints.cx]
Sent: Sunday, September 17, 2000 11:39 AM
To: python-list at python.org
Subject: MicroThread (uthread) queue

Hey all, I'm messing around with Stackless and MicroThreads, and I'm
the best way to set up a queue system with them. There's one main
queue, and I'd like to be able to say 'maintain X threads running
but the problem is the way the uthread API works - you have to set up
many functions you want to run all at the same time, and then run them all -

the uthread.run() function blocks until _all_ the threads are finished. This
a problem, since some of my functions might block for a minute or so, while
others will only take about a second. Thanks for any suggestions :)

Chris Armstrong          http://www.penguinmints.cx
punck at PenguinMints.cx
There is a 90% chance that this message was written when the author's been
awake longer than he should have. Please disregard any senseless drivel.

More information about the Python-list mailing list