分类: Python/Ruby
2013-12-18 23:35:26
import threading
import time,random
class ThreadLocal(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.local = threading.local()
def run(self):
time.sleep(random.random())
self.local.number=[]
for i in range(10):
self.local.number.append(random.choice(range(10)))
print threading.currentThread(),self.local.number
threadLocal=ThreadLocal()
threads=[]
for index in range(5):
thread = threading.Thread(target=threadLocal.run)
thread.start()
threads.append(thread)
for i in range(5):
threads[i].join
print "Main Thread exit...."
Main Thread exit....