分类: Python/Ruby
2013-12-18 23:20:15
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)
for index in range(5):
thread = ThreadTest(index,time.time())
thread.start()
print "Main Thread exit...."
Main Thread exit....
1.00253081322 0
1.00250315666 2
1.00263309479 1
Thread 2 exit....
Thread 1 exit....
Thread 0 exit....
1.00520896912 3
Thread 3 exit....
1.00583481789 4
Thread 4 exit....