mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-16 16:15:22 +03:00
Use util.Process facilities in AudioProcessor
Boilerplate begone!
This commit is contained in:
parent
fe84887095
commit
7092ca3505
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import signal
|
|
||||||
import sys
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
@ -73,46 +71,42 @@ class AudioProcessor(util.Process):
|
|||||||
):
|
):
|
||||||
super().__init__(name="frigate.audio_manager", daemon=True)
|
super().__init__(name="frigate.audio_manager", daemon=True)
|
||||||
|
|
||||||
self.logger = logging.getLogger(self.name)
|
|
||||||
self.camera_metrics = camera_metrics
|
self.camera_metrics = camera_metrics
|
||||||
self.cameras = cameras
|
self.cameras = cameras
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
stop_event = threading.Event()
|
|
||||||
audio_threads: list[AudioEventMaintainer] = []
|
audio_threads: list[AudioEventMaintainer] = []
|
||||||
|
|
||||||
threading.current_thread().name = "process:audio_manager"
|
threading.current_thread().name = "process:audio_manager"
|
||||||
signal.signal(signal.SIGTERM, lambda sig, frame: sys.exit())
|
|
||||||
|
|
||||||
if len(self.cameras) == 0:
|
if len(self.cameras) == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
for camera in self.cameras:
|
||||||
for camera in self.cameras:
|
audio_thread = AudioEventMaintainer(
|
||||||
audio_thread = AudioEventMaintainer(
|
camera,
|
||||||
camera,
|
self.camera_metrics,
|
||||||
self.camera_metrics,
|
self.stop_event,
|
||||||
stop_event,
|
)
|
||||||
)
|
audio_threads.append(audio_thread)
|
||||||
audio_threads.append(audio_thread)
|
audio_thread.start()
|
||||||
audio_thread.start()
|
|
||||||
|
|
||||||
self.logger.info(f"Audio processor started (pid: {self.pid})")
|
self.logger.info(f"Audio processor started (pid: {self.pid})")
|
||||||
|
|
||||||
while True:
|
while not self.stop_event.wait():
|
||||||
signal.pause()
|
pass
|
||||||
finally:
|
|
||||||
stop_event.set()
|
|
||||||
for thread in audio_threads:
|
|
||||||
thread.join(1)
|
|
||||||
if thread.is_alive():
|
|
||||||
self.logger.info(f"Waiting for thread {thread.name:s} to exit")
|
|
||||||
thread.join(10)
|
|
||||||
|
|
||||||
for thread in audio_threads:
|
for thread in audio_threads:
|
||||||
if thread.is_alive():
|
thread.join(1)
|
||||||
self.logger.warning(f"Thread {thread.name} is still alive")
|
if thread.is_alive():
|
||||||
self.logger.info("Exiting audio processor")
|
self.logger.info(f"Waiting for thread {thread.name:s} to exit")
|
||||||
|
thread.join(10)
|
||||||
|
|
||||||
|
for thread in audio_threads:
|
||||||
|
if thread.is_alive():
|
||||||
|
self.logger.warning(f"Thread {thread.name} is still alive")
|
||||||
|
|
||||||
|
self.logger.info("Exiting audio processor")
|
||||||
|
|
||||||
|
|
||||||
class AudioEventMaintainer(threading.Thread):
|
class AudioEventMaintainer(threading.Thread):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user