Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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 检查queue.empty()会产生令人费解的行为_Python_Multithreading - Fatal编程技术网

Python 检查queue.empty()会产生令人费解的行为

Python 检查queue.empty()会产生令人费解的行为,python,multithreading,Python,Multithreading,我使用多个线程从多个传感器以不同的采集速率提取数据。我有一个30Hz的摄像头和一个200Hz的多轴IMU。在收集数据的方法中,我进行了一些基线处理,并将数据推送到一个队列中供主代码使用 我主要从以下几点开始。camq、inerq和plotq都是Queue.Queue()对象。cammer、inertial和plotter都是无限循环收集数据并将其推入队列的方法 t1 = Thread(target=cammer, args = (camq,)) t2 = Thread(target = iner

我使用多个线程从多个传感器以不同的采集速率提取数据。我有一个30Hz的摄像头和一个200Hz的多轴IMU。在收集数据的方法中,我进行了一些基线处理,并将数据推送到一个队列中供主代码使用

我主要从以下几点开始。camq、inerq和plotq都是Queue.Queue()对象。cammer、inertial和plotter都是无限循环收集数据并将其推入队列的方法

t1 = Thread(target=cammer, args = (camq,))
t2 = Thread(target = inertial, args = (inerq,))
t3 = Thread(target = plotter, args = (plotq,))
t1.setDaemon(True)
t2.setDaemon(True)
t3.setDaemon(True)
t1.start()
t2.start()
t3.start()
我的应用程序的关键值是IMU值。因此,在我的主代码中的无限循环中,调整项目是读取这些值的队列。我的问题是,我不想在代码继续执行之前等待摄影机队列填充。因此,我在主代码中完成了以下操作:

while True:
    result = inerq.get() #Get the inertial data as it comes

    #Many lines of inertial processing code

    if not camq.empty(): #Check if the camera queue is empty
        if camq.get_nowait() >297 and camq.get_nowait() <303: #If it isn't empty poll it to see if it meets the criteria.

            #Many lines of kalman filtering
为True时:
result=inerq.get()#获取惯性数据
#多行惯性处理代码
如果不是camq.empty():#检查摄像机队列是否为空

如果camq.get\u nowait()>297和camq.get\u nowait()
camq.get\u nowait()。
if camq.get() >297 and camq.get() <303: #Poll the camera data

            #Many lines of kalman filtering