frigate/frigate/watchdog.py

40 lines
1.2 KiB
Python
Raw Normal View History

2020-11-02 00:45:04 +03:00
import datetime
2020-11-04 06:26:39 +03:00
import logging
2020-11-02 00:45:04 +03:00
import threading
2020-11-04 15:31:25 +03:00
import time
import os
import signal
2020-11-02 00:45:04 +03:00
2021-09-18 15:40:27 +03:00
from frigate.util import (
restart_frigate,
)
2020-11-04 06:26:39 +03:00
logger = logging.getLogger(__name__)
2021-02-17 16:23:32 +03:00
2020-11-02 00:45:04 +03:00
class FrigateWatchdog(threading.Thread):
def __init__(self, detectors, stop_event):
threading.Thread.__init__(self)
2021-02-17 16:23:32 +03:00
self.name = "frigate_watchdog"
2020-11-02 00:45:04 +03:00
self.detectors = detectors
self.stop_event = stop_event
def run(self):
time.sleep(10)
while not self.stop_event.wait(10):
2020-11-02 00:45:04 +03:00
now = datetime.datetime.now().timestamp()
# check the detection processes
for detector in self.detectors.values():
detection_start = detector.detection_start.value
2021-02-17 16:23:32 +03:00
if detection_start > 0.0 and now - detection_start > 10:
logger.info(
"Detection appears to be stuck. Restarting detection process..."
)
2020-11-02 00:45:04 +03:00
detector.start_or_restart()
elif not detector.detect_process.is_alive():
2021-02-13 18:56:26 +03:00
logger.info("Detection appears to have stopped. Exiting frigate...")
2021-09-18 15:40:27 +03:00
restart_frigate()
logger.info(f"Exiting watchdog...")