我打算使用python的线程/队列2.5.2 但似乎python冻结在queue.join() - 命令。 的followong代码的输出仅仅是:BEFOREPython中的线程/队列
import Queue
import threading
queue = Queue.Queue()
class ThreadUrl(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = queue
def run(self):
while True:
i = self.queue.get()
print i
self.queue.task_done()
def main():
for i in range(5):
t = ThreadUrl(queue)
t.setDaemon(True)
t.start()
for i in range(5):
queue.put(i)
print "BEFORE"
queue.join()
print "AFTER"
main()
有某人什么错误的想法?
queue.put(1)...不是说这是解决方案。但只是检查编号(队列)是相同的所有功能...如果没有,然后使用全局队列的功能... –
这适用于我在Python上使用Python 2.6.6 –
此代码看起来非常完美,我整天阅读这些东西:\ –