首页 > 代码库 > python threading queue

python threading queue

 

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()        returnque = queue.Queue()for x in range(200):    que.put(x)for x in range(3):    t=MyThread()    t.start()que.join()