网站被百度k掉怎么办,天津手机网站制作,做小程序的公司,wordpress关键字查询我对python多线程队列有问题。我有一个脚本#xff0c;其中producer从输入队列获取元素#xff0c;生成一些元素并将它们放入输出队列#xff0c;consumer从输出队列获取元素并打印它们#xff1a;import threadingimport Queueclass Producer(threading.Thread):def __ini…我对python多线程队列有问题。我有一个脚本其中producer从输入队列获取元素生成一些元素并将它们放入输出队列consumer从输出队列获取元素并打印它们import threadingimport Queueclass Producer(threading.Thread):def __init__(self, iq, oq):threading.Thread.__init__(self)self.iq iqself.oq oqdef produce(self, e):self.oq.put(e*2)self.oq.task_done()print Producer %s produced %d and put it to output Queue%(self.getName(), e*2)def run(self):while 1:e self.iq.get()self.iq.task_done()print Get %d from input Queue%(e)self.produce(e)class Consumer(threading.Thread):def __init__(self, oq):threading.Thread.__init__(self)self.oq oqdef run(self):while 1:e self.oq.get()self.oq.task_done()print Consumer get %d from output queue and consumed%eiq Queue.Queue()oq Queue.Queue()for i in xrange(2):iq.put((i1)*10)for i in xrange(2):t1 Producer(iq, oq)t1.setDaemon(True)t1.start()t2 Consumer(oq)t2.setDaemon(True)t2.start()iq.join()oq.join()但是每次我运行它时它的工作方式都不同(给出异常或者消费者不做任何工作)。我认为问题出在task_done()命令中有人能解释一下bug在哪里吗我修改了消费类class Consumer(threading.Thread):def __init__(self, oq):threading.Thread.__init__(self)self.oq oqdef run(self):while 1:e self.oq.get()self.oq.task_done()print Consumer get %d from output queue and consumed%epage urllib2.urlopen(http://www.ifconfig.me/ip)print page现在每个task_done()命令之后的使用者都应该连接到网站(这需要一些时间)但它不需要相反如果task_done()之后的代码执行时间很短它会运行但如果很长它不会运行为什么有人能解释一下这个问题吗如果我把所有的东西都放在task_done()命令之前那么我将从其他线程中阻塞队列这已经足够愚蠢了。或者在python中的多线程有什么我遗漏的吗