#!/usr/local/bin/python import time, threading, whrandom class MyThread(threading.Thread): """ Each thread picks a 'random' integer between 0 and 10 and reports in once per second for that many seconds. """ def run(self): iterations = whrandom.randint(0, 10) for i in range(iterations): print " ", self.getName(), "is reporting in" time.sleep(1) print self.getName(), "is DONE" if __name__ == '__main__': threadList = [] # Create 5 MyThread() threads for i in range(5) : thread = MyThread() threadList.append(thread) # Start all threads for thread in threadList: thread.start() # As long as we have more than just the 'main' thread running, print # out a status message while threading.activeCount() > 1 : print str(threading.activeCount()), "threads running incl. main" time.sleep(1)