From 580f35112e85249caded199c724353a417eba743 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:47:46 -0600 Subject: [PATCH] revert changes to audio process to prevent shutdown hang (#14872) --- frigate/app.py | 14 +++++++++----- frigate/events/audio.py | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/frigate/app.py b/frigate/app.py index d0d3ab8a1..7543aef30 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -63,7 +63,6 @@ from frigate.record.cleanup import RecordingCleanup from frigate.record.export import migrate_exports from frigate.record.record import manage_recordings from frigate.review.review import manage_review_segments -from frigate.service_manager import ServiceManager from frigate.stats.emitter import StatsEmitter from frigate.stats.util import stats_init from frigate.storage import StorageMaintainer @@ -79,6 +78,7 @@ logger = logging.getLogger(__name__) class FrigateApp: def __init__(self, config: FrigateConfig) -> None: + self.audio_process: Optional[mp.Process] = None self.stop_event: MpEvent = mp.Event() self.detection_queue: Queue = mp.Queue() self.detectors: dict[str, ObjectDetectProcess] = {} @@ -449,8 +449,9 @@ class FrigateApp: ] if audio_cameras: - proc = AudioProcessor(audio_cameras, self.camera_metrics).start(wait=True) - self.processes["audio_detector"] = proc.pid or 0 + self.audio_process = AudioProcessor(audio_cameras, self.camera_metrics) + self.audio_process.start() + self.processes["audio_detector"] = self.audio_process.pid or 0 def start_timeline_processor(self) -> None: self.timeline_processor = TimelineProcessor( @@ -641,6 +642,11 @@ class FrigateApp: ReviewSegment.end_time == None ).execute() + # stop the audio process + if self.audio_process: + self.audio_process.terminate() + self.audio_process.join() + # ensure the capture processes are done for camera, metrics in self.camera_metrics.items(): capture_process = metrics.capture_process @@ -709,6 +715,4 @@ class FrigateApp: shm.close() shm.unlink() - ServiceManager.current().shutdown(wait=True) - os._exit(os.EX_OK) diff --git a/frigate/events/audio.py b/frigate/events/audio.py index 45706dcc8..80d035894 100644 --- a/frigate/events/audio.py +++ b/frigate/events/audio.py @@ -9,6 +9,7 @@ from typing import Tuple import numpy as np import requests +import frigate.util as util from frigate.camera import CameraMetrics from frigate.comms.config_updater import ConfigSubscriber from frigate.comms.detections_updater import DetectionPublisher, DetectionTypeEnum @@ -25,7 +26,6 @@ from frigate.const import ( from frigate.ffmpeg_presets import parse_preset_input from frigate.log import LogPipe from frigate.object_detection import load_labels -from frigate.service_manager import ServiceProcess from frigate.util.builtin import get_ffmpeg_arg_list from frigate.video import start_or_restart_ffmpeg, stop_ffmpeg @@ -63,7 +63,7 @@ def get_ffmpeg_command(ffmpeg: FfmpegConfig) -> list[str]: ) -class AudioProcessor(ServiceProcess): +class AudioProcessor(util.Process): name = "frigate.audio_manager" def __init__( @@ -71,7 +71,7 @@ class AudioProcessor(ServiceProcess): cameras: list[CameraConfig], camera_metrics: dict[str, CameraMetrics], ): - super().__init__() + super().__init__(name="frigate.audio_manager", daemon=True) self.camera_metrics = camera_metrics self.cameras = cameras