Python多线程简单例子

import threading
import Queue

class Test(threading.Thread):
    def __init__(self, q): 
        self.queue = q 
        threading.Thread.__init__(self)

    def run(self):
        while True:
            event = self.queue.get()
            if event is None:
                break
            print str(event)

queue = Queue.Queue(100)
for i in range(10):
    t = Test(queue)
    t.start()

for i in range(10):
    queue.put(i)

for i in range(10):
    queue.put(None)

 

posted @ 2018-04-24 18:34  jhc888007  阅读(110)  评论(0编辑  收藏  举报