import queue,threading l=threading.Lock() class MyThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) global que self.queue = que def run(self): while True: if self.queue.empty(): break item = self.queue.get() if l.acquire(1): print( self.name,item) l.release() self.queue.task_done() return que = queue.Queue() for x in range(200): que.put(x) for x in range(3): t=MyThread() t.start() que.join()
python threading queue,布布扣,bubuko.com
原文:http://www.cnblogs.com/qingda/p/3858419.html