我正在尝试使用 concurrent.futres.ProcessPoolExecuter 运行代码,但在运行视频时遇到下面提到的while true
错误class get_frames
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
下面提到的是我的实际代码:
import cv2
import numpy as np
import imutils
import os
import threading
import concurrent.futures
import time
start = time.perf_counter()
class VideoCapture:
def __init__(self, name):
self.cap = cv2.VideoCapture(name)
self.q = queue.Queue()
t = threading.Thread(target=self._reader)
# t.get_ident()
t.start()
t.daemon = True
# read frames as soon as they are available, keeping only most recent one
def _reader(self):
while True:
ret, frame = self.cap.read()
if not ret:
break
if not self.q.empty():
try:
self.q.get_nowait() # discard previous (unprocessed) frame
except Queue.Empty:
pass
self.q.put(frame)
@classmethod
def read(cls):
return cls(self.q.get())
names = ['test.mp4', 'test1.mp4']
frames = [None] * len(names);
#frame_in = [None] * len(names);
ret = [None] * len(names);
cap_list = [cv2.VideoCapture(k) for k in names]
# print(cap_list)
class get_frames:
def __init__(self, cap, name):
self.cap = cap
self.name = name
# print(self.cap)
def display_frames(self):
while True:
ret, frames = self.cap.read()
if ret is True:
count += 1
print(self.name)
with concurrent.futures.ProcessPoolExecutor(max_workers=3) as executor:
for i, cap in enumerate(cap_list):
g_f = get_frames(cap, i)
results = executor.map(g_f.display_frames, cap_list)
print(results)
对此的任何建议都会有很大帮助