1

私は、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)

これに関する提案は大きな助けになります

4

1 に答える 1