Add short delay to reduce CPU usage when the queue is empty in frigate object detection, output, and video modules

This commit is contained in:
Sergey Krashevich 2023-06-23 02:45:40 +03:00
parent 9e531b0b5b
commit e72a315893
No known key found for this signature in database
GPG Key ID: 625171324E7D3856
3 changed files with 5 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import queue
import signal
import threading
from abc import ABC, abstractmethod
import time
import numpy as np
from setproctitle import setproctitle
@ -106,6 +107,7 @@ def run_detector(
try:
connection_id = detection_queue.get(timeout=1)
except queue.Empty:
time.sleep(0.01) # short delay to reduce CPU usage when the queue is empty
continue
input_frame = frame_manager.get(
connection_id,

View File

@ -8,6 +8,7 @@ import queue
import signal
import subprocess as sp
import threading
import time
import traceback
from wsgiref.simple_server import make_server
@ -598,6 +599,7 @@ def output_frames(config: FrigateConfig, video_output_queue):
regions,
) = video_output_queue.get(True, 1)
except queue.Empty:
time.sleep(0.01) # short delay to reduce CPU usage when the queue is empty
continue
frame_id = f"{camera}{frame_time}"

View File

@ -750,6 +750,7 @@ def process_frames(
try:
frame_time = frame_queue.get(True, 1)
except queue.Empty:
time.sleep(0.01) # short delay to reduce CPU usage when the queue is empty
continue
current_frame_time.value = frame_time