# Let's use the threading module. # BTW, the function time.ctime() is useful to print out current system time. import time import threading class myThread(threading.Thread): # The constructor is the place to identify attributes of each specific thread. def __init__(self, myNumber): threading.Thread.__init__(self) self.number = myNumber print "Initializing thread " + str(self.number) # run() defines the work that the thread is supposed to do # To simulate work, let's just "sleep" for 2 seconds. def run(self): print "Thread " + str(self.number) + " is starting :)" time.sleep(2) print "Thread " + str(self.number) + " is finished" # main program print "\nProgram starts: " + time.ctime() threadList = [] for i in range(1, 5): currentThread = myThread(i) threadList.append(currentThread) currentThread.start() # Tell the main program to wait for all threads to finish for t in threadList: t.join() print "All done at " + time.ctime()