MicroThread (uthread) queue

Mike Fletcher mfletch at tpresence.com
Sun Sep 17 12:59:03 EDT 2000


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


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

uthread9.new( appMainLoop )
uthread9.run()

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

Enjoy,
Mike

-----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
ponderring
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
concurrently',
but the problem is the way the uthread API works - you have to set up
however
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
is
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.
-- 
http://www.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list