mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-15 07:35:27 +03:00
Maintain a logger and stop_event in util.Process
This commit is contained in:
parent
e576f991c8
commit
37ea7663bb
@ -1,7 +1,9 @@
|
|||||||
import logging
|
import logging
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
|
import signal
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from logging.handlers import QueueHandler
|
from logging.handlers import QueueHandler
|
||||||
|
from multiprocessing.synchronize import Event
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import frigate.log
|
import frigate.log
|
||||||
@ -46,6 +48,9 @@ class BaseProcess(mp.Process):
|
|||||||
|
|
||||||
|
|
||||||
class Process(BaseProcess):
|
class Process(BaseProcess):
|
||||||
|
logger: logging.Logger
|
||||||
|
stop_event: Event
|
||||||
|
|
||||||
def before_start(self) -> None:
|
def before_start(self) -> None:
|
||||||
self.__log_queue = frigate.log.log_listener.queue
|
self.__log_queue = frigate.log.log_listener.queue
|
||||||
|
|
||||||
@ -53,3 +58,13 @@ class Process(BaseProcess):
|
|||||||
if self.__log_queue:
|
if self.__log_queue:
|
||||||
logging.basicConfig(handlers=[], force=True)
|
logging.basicConfig(handlers=[], force=True)
|
||||||
logging.getLogger().addHandler(QueueHandler(self.__log_queue))
|
logging.getLogger().addHandler(QueueHandler(self.__log_queue))
|
||||||
|
|
||||||
|
self.logger = logging.getLogger(self.name)
|
||||||
|
|
||||||
|
self.stop_event = mp.Event()
|
||||||
|
|
||||||
|
def receiveSignal(signalNumber, frame):
|
||||||
|
self.stop_event.set()
|
||||||
|
|
||||||
|
signal.signal(signal.SIGTERM, receiveSignal)
|
||||||
|
signal.signal(signal.SIGINT, receiveSignal)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user