From 09c39f80408c5421ea756e2bfbb17270704174f3 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Fri, 3 Feb 2023 08:39:13 -0700 Subject: [PATCH] Disable detect in config before restart --- frigate/comms/dispatcher.py | 2 +- frigate/http.py | 2 +- frigate/util.py | 7 ++++++- frigate/watchdog.py | 9 +++++---- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/frigate/comms/dispatcher.py b/frigate/comms/dispatcher.py index aab011fe9..74513d956 100644 --- a/frigate/comms/dispatcher.py +++ b/frigate/comms/dispatcher.py @@ -65,7 +65,7 @@ class Dispatcher: logger.error(f"Received invalid set command: {topic}") return elif topic == "restart": - restart_frigate() + restart_frigate(self.config) def publish(self, topic: str, payload: Any, retain: bool = False) -> None: """Handle publishing to communicators.""" diff --git a/frigate/http.py b/frigate/http.py index 4ae4d4d95..b53ec3f06 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -764,7 +764,7 @@ def config_save(): if save_option == "restart": try: - restart_frigate() + restart_frigate(current_app.frigate_config) except Exception as e: logging.error(f"Error restarting Frigate: {e}") return "Config successfully saved, unable to restart Frigate", 200 diff --git a/frigate/util.py b/frigate/util.py index 69ead2a7a..e28d84f21 100755 --- a/frigate/util.py +++ b/frigate/util.py @@ -22,6 +22,7 @@ import os import psutil import pytz +from frigate.config import FrigateConfig from frigate.const import REGEX_HTTP_CAMERA_USER_PASS, REGEX_RTSP_CAMERA_USER_PASS logger = logging.getLogger(__name__) @@ -627,7 +628,11 @@ def clipped(obj, frame_shape): return False -def restart_frigate(): +def restart_frigate(config: FrigateConfig): + # disable detect for cameras to speed up restart + for _, camera in config.cameras.items(): + camera.detect.enabled = False + proc = psutil.Process(1) # if this is running via s6, sigterm pid 1 if proc.name() == "s6-svscan": diff --git a/frigate/watchdog.py b/frigate/watchdog.py index 5df826f0e..a5b9eb9ed 100644 --- a/frigate/watchdog.py +++ b/frigate/watchdog.py @@ -2,20 +2,21 @@ import datetime import logging import threading import time -import os -import signal +from multiprocessing.synchronize import Event as MpEvent + +from frigate.config import FrigateConfig from frigate.object_detection import ObjectDetectProcess from frigate.util import restart_frigate -from multiprocessing.synchronize import Event as MpEvent logger = logging.getLogger(__name__) class FrigateWatchdog(threading.Thread): - def __init__(self, detectors: dict[str, ObjectDetectProcess], stop_event: MpEvent): + def __init__(self, config: FrigateConfig, detectors: dict[str, ObjectDetectProcess], stop_event: MpEvent): threading.Thread.__init__(self) self.name = "frigate_watchdog" + self.config = config self.detectors = detectors self.stop_event = stop_event