mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-15 15:45:27 +03:00
Switch app stop_event to use threading.Event
This commit is contained in:
parent
af39439546
commit
42103ebfb5
@ -4,7 +4,7 @@ import multiprocessing as mp
|
|||||||
import os
|
import os
|
||||||
import secrets
|
import secrets
|
||||||
import shutil
|
import shutil
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
import threading
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
@ -77,7 +77,7 @@ class FrigateApp:
|
|||||||
|
|
||||||
# TODO: Fix FrigateConfig usage, so we can properly annotate it here without mypy erroring out.
|
# TODO: Fix FrigateConfig usage, so we can properly annotate it here without mypy erroring out.
|
||||||
def __init__(self, config: Any) -> None:
|
def __init__(self, config: Any) -> None:
|
||||||
self.stop_event: MpEvent = mp.Event()
|
self.stop_event = threading.Event()
|
||||||
self.detection_queue: mp.Queue = mp.Queue()
|
self.detection_queue: mp.Queue = mp.Queue()
|
||||||
self.detectors: dict[str, ObjectDetectProcess] = {}
|
self.detectors: dict[str, ObjectDetectProcess] = {}
|
||||||
self.detection_shms: list[mp.shared_memory.SharedMemory] = []
|
self.detection_shms: list[mp.shared_memory.SharedMemory] = []
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from frigate.config import FrigateConfig
|
from frigate.config import FrigateConfig
|
||||||
@ -22,7 +21,7 @@ class EventCleanupType(str, Enum):
|
|||||||
|
|
||||||
|
|
||||||
class EventCleanup(threading.Thread):
|
class EventCleanup(threading.Thread):
|
||||||
def __init__(self, config: FrigateConfig, stop_event: MpEvent):
|
def __init__(self, config: FrigateConfig, stop_event: threading.Event):
|
||||||
super().__init__(name="event_cleanup")
|
super().__init__(name="event_cleanup")
|
||||||
self.config = config
|
self.config = config
|
||||||
self.stop_event = stop_event
|
self.stop_event = stop_event
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
from multiprocessing import Queue
|
from multiprocessing import Queue
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from frigate.comms.events_updater import EventEndPublisher, EventUpdateSubscriber
|
from frigate.comms.events_updater import EventEndPublisher, EventUpdateSubscriber
|
||||||
@ -52,7 +51,7 @@ class EventProcessor(threading.Thread):
|
|||||||
self,
|
self,
|
||||||
config: FrigateConfig,
|
config: FrigateConfig,
|
||||||
timeline_queue: Queue,
|
timeline_queue: Queue,
|
||||||
stop_event: MpEvent,
|
stop_event: threading.Event,
|
||||||
):
|
):
|
||||||
super().__init__(name="event_processor")
|
super().__init__(name="event_processor")
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import os
|
|||||||
import queue
|
import queue
|
||||||
import threading
|
import threading
|
||||||
from collections import Counter, defaultdict
|
from collections import Counter, defaultdict
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
|
||||||
from statistics import median
|
from statistics import median
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
@ -919,13 +918,13 @@ class TrackedObjectProcessor(threading.Thread):
|
|||||||
dispatcher: Dispatcher,
|
dispatcher: Dispatcher,
|
||||||
tracked_objects_queue,
|
tracked_objects_queue,
|
||||||
ptz_autotracker_thread,
|
ptz_autotracker_thread,
|
||||||
stop_event,
|
stop_event: threading.Event,
|
||||||
):
|
):
|
||||||
super().__init__(name="detected_frames_processor")
|
super().__init__(name="detected_frames_processor")
|
||||||
self.config = config
|
self.config = config
|
||||||
self.dispatcher = dispatcher
|
self.dispatcher = dispatcher
|
||||||
self.tracked_objects_queue = tracked_objects_queue
|
self.tracked_objects_queue = tracked_objects_queue
|
||||||
self.stop_event: MpEvent = stop_event
|
self.stop_event = stop_event
|
||||||
self.camera_states: dict[str, CameraState] = {}
|
self.camera_states: dict[str, CameraState] = {}
|
||||||
self.frame_manager = SharedMemoryFrameManager()
|
self.frame_manager = SharedMemoryFrameManager()
|
||||||
self.last_motion_detected: dict[str, float] = {}
|
self.last_motion_detected: dict[str, float] = {}
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import datetime
|
|||||||
import glob
|
import glob
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
import multiprocessing as mp
|
|
||||||
import os
|
import os
|
||||||
import queue
|
import queue
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
@ -114,7 +113,7 @@ class FFMpegConverter(threading.Thread):
|
|||||||
self,
|
self,
|
||||||
ffmpeg: FfmpegConfig,
|
ffmpeg: FfmpegConfig,
|
||||||
input_queue: queue.Queue,
|
input_queue: queue.Queue,
|
||||||
stop_event: mp.Event,
|
stop_event: threading.Event,
|
||||||
in_width: int,
|
in_width: int,
|
||||||
in_height: int,
|
in_height: int,
|
||||||
out_width: int,
|
out_width: int,
|
||||||
@ -232,7 +231,7 @@ class BroadcastThread(threading.Thread):
|
|||||||
camera: str,
|
camera: str,
|
||||||
converter: FFMpegConverter,
|
converter: FFMpegConverter,
|
||||||
websocket_server,
|
websocket_server,
|
||||||
stop_event: mp.Event,
|
stop_event: threading.Event,
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.camera = camera
|
self.camera = camera
|
||||||
@ -269,7 +268,7 @@ class BirdsEyeFrameManager:
|
|||||||
self,
|
self,
|
||||||
config: FrigateConfig,
|
config: FrigateConfig,
|
||||||
frame_manager: SharedMemoryFrameManager,
|
frame_manager: SharedMemoryFrameManager,
|
||||||
stop_event: mp.Event,
|
stop_event: threading.Event,
|
||||||
):
|
):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.mode = config.birdseye.mode
|
self.mode = config.birdseye.mode
|
||||||
@ -718,7 +717,7 @@ class Birdseye:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
config: FrigateConfig,
|
config: FrigateConfig,
|
||||||
stop_event: mp.Event,
|
stop_event: threading.Event,
|
||||||
websocket_server,
|
websocket_server,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
"""Handle outputting individual cameras via jsmpeg."""
|
"""Handle outputting individual cameras via jsmpeg."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import multiprocessing as mp
|
|
||||||
import queue
|
import queue
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
import threading
|
import threading
|
||||||
@ -17,7 +16,7 @@ class FFMpegConverter(threading.Thread):
|
|||||||
camera: str,
|
camera: str,
|
||||||
ffmpeg: FfmpegConfig,
|
ffmpeg: FfmpegConfig,
|
||||||
input_queue: queue.Queue,
|
input_queue: queue.Queue,
|
||||||
stop_event: mp.Event,
|
stop_event: threading.Event,
|
||||||
in_width: int,
|
in_width: int,
|
||||||
in_height: int,
|
in_height: int,
|
||||||
out_width: int,
|
out_width: int,
|
||||||
@ -99,7 +98,7 @@ class BroadcastThread(threading.Thread):
|
|||||||
camera: str,
|
camera: str,
|
||||||
converter: FFMpegConverter,
|
converter: FFMpegConverter,
|
||||||
websocket_server,
|
websocket_server,
|
||||||
stop_event: mp.Event,
|
stop_event: threading.Event,
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.camera = camera
|
self.camera = camera
|
||||||
@ -133,7 +132,7 @@ class BroadcastThread(threading.Thread):
|
|||||||
|
|
||||||
class JsmpegCamera:
|
class JsmpegCamera:
|
||||||
def __init__(
|
def __init__(
|
||||||
self, config: CameraConfig, stop_event: mp.Event, websocket_server
|
self, config: CameraConfig, stop_event: threading.Event, websocket_server
|
||||||
) -> None:
|
) -> None:
|
||||||
self.config = config
|
self.config = config
|
||||||
self.input = queue.Queue(maxsize=config.detect.fps)
|
self.input = queue.Queue(maxsize=config.detect.fps)
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import threading
|
|||||||
import time
|
import time
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -147,7 +146,7 @@ class PtzAutoTrackerThread(threading.Thread):
|
|||||||
onvif: OnvifController,
|
onvif: OnvifController,
|
||||||
ptz_metrics: dict[str, PTZMetrics],
|
ptz_metrics: dict[str, PTZMetrics],
|
||||||
dispatcher: Dispatcher,
|
dispatcher: Dispatcher,
|
||||||
stop_event: MpEvent,
|
stop_event: threading.Event,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(name="ptz_autotracker")
|
super().__init__(name="ptz_autotracker")
|
||||||
self.ptz_autotracker = PtzAutoTracker(
|
self.ptz_autotracker = PtzAutoTracker(
|
||||||
@ -180,7 +179,7 @@ class PtzAutoTracker:
|
|||||||
onvif: OnvifController,
|
onvif: OnvifController,
|
||||||
ptz_metrics: PTZMetrics,
|
ptz_metrics: PTZMetrics,
|
||||||
dispatcher: Dispatcher,
|
dispatcher: Dispatcher,
|
||||||
stop_event: MpEvent,
|
stop_event: threading.Event,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.config = config
|
self.config = config
|
||||||
self.onvif = onvif
|
self.onvif = onvif
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import itertools
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||||
@ -22,7 +21,7 @@ logger = logging.getLogger(__name__)
|
|||||||
class RecordingCleanup(threading.Thread):
|
class RecordingCleanup(threading.Thread):
|
||||||
"""Cleanup existing recordings based on retention config."""
|
"""Cleanup existing recordings based on retention config."""
|
||||||
|
|
||||||
def __init__(self, config: FrigateConfig, stop_event: MpEvent) -> None:
|
def __init__(self, config: FrigateConfig, stop_event: threading.Event) -> None:
|
||||||
super().__init__(name="recording_cleanup")
|
super().__init__(name="recording_cleanup")
|
||||||
self.config = config
|
self.config = config
|
||||||
self.stop_event = stop_event
|
self.stop_event = stop_event
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from frigate.comms.inter_process import InterProcessRequestor
|
from frigate.comms.inter_process import InterProcessRequestor
|
||||||
@ -25,7 +24,7 @@ class StatsEmitter(threading.Thread):
|
|||||||
self,
|
self,
|
||||||
config: FrigateConfig,
|
config: FrigateConfig,
|
||||||
stats_tracking: StatsTrackingTypes,
|
stats_tracking: StatsTrackingTypes,
|
||||||
stop_event: MpEvent,
|
stop_event: threading.Event,
|
||||||
):
|
):
|
||||||
super().__init__(name="frigate_stats_emitter")
|
super().__init__(name="frigate_stats_emitter")
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|||||||
@ -21,7 +21,7 @@ bandwidth_equation = Recordings.segment_size / (
|
|||||||
class StorageMaintainer(threading.Thread):
|
class StorageMaintainer(threading.Thread):
|
||||||
"""Maintain frigates recording storage."""
|
"""Maintain frigates recording storage."""
|
||||||
|
|
||||||
def __init__(self, config: FrigateConfig, stop_event) -> None:
|
def __init__(self, config: FrigateConfig, stop_event: threading.Event) -> None:
|
||||||
super().__init__(name="storage_maintainer")
|
super().__init__(name="storage_maintainer")
|
||||||
self.config = config
|
self.config = config
|
||||||
self.stop_event = stop_event
|
self.stop_event = stop_event
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import logging
|
|||||||
import queue
|
import queue
|
||||||
import threading
|
import threading
|
||||||
from multiprocessing import Queue
|
from multiprocessing import Queue
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
|
||||||
|
|
||||||
from frigate.config import FrigateConfig
|
from frigate.config import FrigateConfig
|
||||||
from frigate.events.maintainer import EventTypeEnum
|
from frigate.events.maintainer import EventTypeEnum
|
||||||
@ -21,7 +20,7 @@ class TimelineProcessor(threading.Thread):
|
|||||||
self,
|
self,
|
||||||
config: FrigateConfig,
|
config: FrigateConfig,
|
||||||
queue: Queue,
|
queue: Queue,
|
||||||
stop_event: MpEvent,
|
stop_event: threading.Event,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(name="timeline_processor")
|
super().__init__(name="timeline_processor")
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
|
||||||
|
|
||||||
from frigate.object_detection import ObjectDetectProcess
|
from frigate.object_detection import ObjectDetectProcess
|
||||||
from frigate.util.services import restart_frigate
|
from frigate.util.services import restart_frigate
|
||||||
@ -10,7 +9,9 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class FrigateWatchdog(threading.Thread):
|
class FrigateWatchdog(threading.Thread):
|
||||||
def __init__(self, detectors: dict[str, ObjectDetectProcess], stop_event: MpEvent):
|
def __init__(
|
||||||
|
self, detectors: dict[str, ObjectDetectProcess], stop_event: threading.Event
|
||||||
|
):
|
||||||
super().__init__(name="frigate_watchdog")
|
super().__init__(name="frigate_watchdog")
|
||||||
self.detectors = detectors
|
self.detectors = detectors
|
||||||
self.stop_event = stop_event
|
self.stop_event = stop_event
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user