优化线程池
This commit is contained in:
@@ -69,6 +69,8 @@ class Presenter:
|
||||
self.process2d_info[cfg["title"]] = pro
|
||||
pro.start()
|
||||
|
||||
self.executor = ThreadPoolExecutor(max_workers=8)
|
||||
|
||||
print("DEBUG:init completed")
|
||||
|
||||
# NOTE: 障碍物状态历史队列
|
||||
@@ -125,7 +127,6 @@ class Presenter:
|
||||
# TODO: 避障模式相机采集和数据处理
|
||||
def obstacle_mode_data_handle(self):
|
||||
"""获取所有3D避障相机的数据并处理,直到所有处理完成再继续"""
|
||||
st = time.time()
|
||||
futures = []
|
||||
# 1. 发出CAPTURE命令
|
||||
for key in self.process3d_info.keys():
|
||||
@@ -133,15 +134,15 @@ class Presenter:
|
||||
continue
|
||||
self.process3d_info[key].in_q.put(CameraControl.CAPTURE)
|
||||
|
||||
st = time.time()
|
||||
# 2. 等待图像并提交处理任务
|
||||
while not self.fifo_3d.empty():
|
||||
img_data = self.fifo_3d.get()
|
||||
future = self.executor.submit(self.handle_obstacle_data, img_data)
|
||||
futures.append(future)
|
||||
et = time.time()
|
||||
dua = (et - st) * 1000
|
||||
print(f"[DEBUG]: 采图用时{dua:.2f}ms")
|
||||
with ThreadPoolExecutor(max_workers=4) as executor:
|
||||
# 2. 等待图像并提交处理任务
|
||||
while not self.fifo_3d.empty():
|
||||
img_data = self.fifo_3d.get()
|
||||
future = executor.submit(self.handle_obstacle_data, img_data)
|
||||
futures.append(future)
|
||||
|
||||
# 3. 等待所有算法任务完成(阻塞)
|
||||
for future in as_completed(futures):
|
||||
|
Reference in New Issue
Block a user