分类: Python/Ruby
2013-12-18 23:22:40
import threading
import time
class ThreadTest(threading.Thread):
def __init__(self,index,create_time):
threading.Thread.__init__(self)
self.index = index
self.create_time = create_time
def run(self):
time.sleep(1)
print time.time() - self.create_time,"\t",self.index
print "Thread %d exit...."%(self.index)
threads=[]
for index in range(5):
thread = ThreadTest(index,time.time())
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
print "Main Thread exit...."