July 8th, 2004, 05:13 AM
Join Date: Nov 2003
Location: Cambridge, UK
At the moment your program does not require threads at all. In the for loop it starts a thread then waits for that thread to finish (the join) before starting the next one.
IMO what your require is the use of events.
The principle is that each thread is started (you can use the for loop but drop the join
Then the main program busy waits in a while loop monitoring the events- at this point the main thread and child threads are all running in that time sliced multi-tasking mode. The main thread will wait for each threads event before deciding it has finished.
import threading, time
def __init__(self, data, signal):
self.data = data
self.signal = signal
print "Text -> %s"%(self.data)
listd = ["sup jo", "Do i know you?"]
slaves = 
for x in listd:
sig = threading.Event()
sig.clear() #make sure the event is not set yet
test = Threads(x, sig)
slaves.append((test, sig)) # Keep a copy of the thread and event
for n in slaves: # check each slave
if not n.isSet(): # test to see if the thread has triggered it's event
continue # at least one thread is still running so we continue monitoring
n.join() #just to be sure we have tidied up
slaves.pop(0) # Because I use continue we only get here on index 0
print "A slave is dead"
By the way do you really need the setDaemon in this situation?