-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessing_thread.py
More file actions
39 lines (33 loc) · 1.24 KB
/
Copy pathprocessing_thread.py
File metadata and controls
39 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import asyncio
from queue import Queue
from threading import Thread
from config import logger
from frame_processing import process_frame
class ProcessingThread(Thread):
def __init__(self, result_queue):
super().__init__()
self.result_queue = result_queue
self.frame_queue = Queue()
self.running = True
self.daemon = True
self.loop = asyncio.new_event_loop()
def run(self):
asyncio.set_event_loop(self.loop)
while self.running:
if not self.frame_queue.empty():
frame = self.frame_queue.get()
try:
success = self.loop.run_until_complete(
process_frame(frame, self.result_queue)
)
if not success:
logger.error("Frame processing returned False")
except Exception as e:
logger.error(f"Error in processing thread: {str(e)}")
self.result_queue.put(("error", f"Processing error: {str(e)}"))
def process(self, frame):
self.frame_queue.put(frame.copy())
def stop(self):
logger.info("Stopping processing thread")
self.running = False
self.loop.close()