revert changes to audio process to prevent shutdown hang (#14872)

This commit is contained in:
Josh Hawkins 2024-11-08 12:47:46 -06:00 committed by GitHub
parent 3249ffb273
commit 580f35112e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 8 deletions

View File

@ -63,7 +63,6 @@ from frigate.record.cleanup import RecordingCleanup
from frigate.record.export import migrate_exports from frigate.record.export import migrate_exports
from frigate.record.record import manage_recordings from frigate.record.record import manage_recordings
from frigate.review.review import manage_review_segments from frigate.review.review import manage_review_segments
from frigate.service_manager import ServiceManager
from frigate.stats.emitter import StatsEmitter from frigate.stats.emitter import StatsEmitter
from frigate.stats.util import stats_init from frigate.stats.util import stats_init
from frigate.storage import StorageMaintainer from frigate.storage import StorageMaintainer
@ -79,6 +78,7 @@ logger = logging.getLogger(__name__)
class FrigateApp: class FrigateApp:
def __init__(self, config: FrigateConfig) -> None: def __init__(self, config: FrigateConfig) -> None:
self.audio_process: Optional[mp.Process] = None
self.stop_event: MpEvent = mp.Event() self.stop_event: MpEvent = mp.Event()
self.detection_queue: Queue = mp.Queue() self.detection_queue: Queue = mp.Queue()
self.detectors: dict[str, ObjectDetectProcess] = {} self.detectors: dict[str, ObjectDetectProcess] = {}
@ -449,8 +449,9 @@ class FrigateApp:
] ]
if audio_cameras: if audio_cameras:
proc = AudioProcessor(audio_cameras, self.camera_metrics).start(wait=True) self.audio_process = AudioProcessor(audio_cameras, self.camera_metrics)
self.processes["audio_detector"] = proc.pid or 0 self.audio_process.start()
self.processes["audio_detector"] = self.audio_process.pid or 0
def start_timeline_processor(self) -> None: def start_timeline_processor(self) -> None:
self.timeline_processor = TimelineProcessor( self.timeline_processor = TimelineProcessor(
@ -641,6 +642,11 @@ class FrigateApp:
ReviewSegment.end_time == None ReviewSegment.end_time == None
).execute() ).execute()
# stop the audio process
if self.audio_process:
self.audio_process.terminate()
self.audio_process.join()
# ensure the capture processes are done # ensure the capture processes are done
for camera, metrics in self.camera_metrics.items(): for camera, metrics in self.camera_metrics.items():
capture_process = metrics.capture_process capture_process = metrics.capture_process
@ -709,6 +715,4 @@ class FrigateApp:
shm.close() shm.close()
shm.unlink() shm.unlink()
ServiceManager.current().shutdown(wait=True)
os._exit(os.EX_OK) os._exit(os.EX_OK)

View File

@ -9,6 +9,7 @@ from typing import Tuple
import numpy as np import numpy as np
import requests import requests
import frigate.util as util
from frigate.camera import CameraMetrics from frigate.camera import CameraMetrics
from frigate.comms.config_updater import ConfigSubscriber from frigate.comms.config_updater import ConfigSubscriber
from frigate.comms.detections_updater import DetectionPublisher, DetectionTypeEnum 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.ffmpeg_presets import parse_preset_input
from frigate.log import LogPipe from frigate.log import LogPipe
from frigate.object_detection import load_labels from frigate.object_detection import load_labels
from frigate.service_manager import ServiceProcess
from frigate.util.builtin import get_ffmpeg_arg_list from frigate.util.builtin import get_ffmpeg_arg_list
from frigate.video import start_or_restart_ffmpeg, stop_ffmpeg 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" name = "frigate.audio_manager"
def __init__( def __init__(
@ -71,7 +71,7 @@ class AudioProcessor(ServiceProcess):
cameras: list[CameraConfig], cameras: list[CameraConfig],
camera_metrics: dict[str, CameraMetrics], camera_metrics: dict[str, CameraMetrics],
): ):
super().__init__() super().__init__(name="frigate.audio_manager", daemon=True)
self.camera_metrics = camera_metrics self.camera_metrics = camera_metrics
self.cameras = cameras self.cameras = cameras