Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 一根线卡住了_Python_Multithreading - Fatal编程技术网

Python 一根线卡住了

Python 一根线卡住了,python,multithreading,Python,Multithreading,我编写了一个生产者-消费者脚本,其中有两个队列(比如q1和q2)。脚本中有两个生产者从q1中读取数据,并在q2中对一些已处理的值进行更正,现在还有另外两个消费者从q2中读取值,并根据某些已定义的条件打印一些值。所有这四个线程都并行运行。我面临着一个与消费者有关的问题,在阅读完第二季度的所有价值后,它陷入了困境。终止使用者的条件是,如果生产者和q2都已终止,并且q2为空,但当我运行此脚本时,它会被其中一个使用者线程卡住(例如,如果consumer1完成,则consumer2卡住,反之亦然) 有人能

我编写了一个生产者-消费者脚本,其中有两个队列(比如q1和q2)。脚本中有两个生产者从q1中读取数据,并在q2中对一些已处理的值进行更正,现在还有另外两个消费者从q2中读取值,并根据某些已定义的条件打印一些值。所有这四个线程都并行运行。我面临着一个与消费者有关的问题,在阅读完第二季度的所有价值后,它陷入了困境。终止使用者的条件是,如果生产者和q2都已终止,并且q2为空,但当我运行此脚本时,它会被其中一个使用者线程卡住(例如,如果consumer1完成,则consumer2卡住,反之亦然)

有人能帮我吗? 提前谢谢

class WorkflowProducer1:
    def __init__(self,coord_q,wf_q):
        self.coord_q=coord_q
        self.wf_q=wf_q

    def wf_produce1(self):
        while not self.coord_q.empty():
            coord_id=self.coord_q.get()
            wf_id=workflow_finder(coord_id)
            if wf_id!='':
                self.wf_q.put(wf_id)
        if self.coord_q.empty():
            print("producer 1 finished")


class WorkflowConsumer1:
    def __init__(self,wf_q):
        self.wf_q=wf_q

    def wf_consume1(self):
        while not self.wf_q.empty() or thread1.is_alive() or thread2.is_live():
            wf_id=self.wf_q.get()
            workflow_validator(wf_id)