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()
        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

python threading queue

上一篇:Search in Rotated Sorted Array leetcode java


下一篇:Java安全机制之泛型(JDK1.5)