Switch app stop_event to use threading.Event

This commit is contained in:
George Tsiamasiotis 2024-10-02 19:14:31 +03:00
parent af39439546
commit 42103ebfb5
12 changed files with 22 additions and 30 deletions

View File

@ -4,7 +4,7 @@ import multiprocessing as mp
import os
import secrets
import shutil
from multiprocessing.synchronize import Event as MpEvent
import threading
from typing import Any, Optional
import psutil
@ -77,7 +77,7 @@ class FrigateApp:
# TODO: Fix FrigateConfig usage, so we can properly annotate it here without mypy erroring out.
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.detectors: dict[str, ObjectDetectProcess] = {}
self.detection_shms: list[mp.shared_memory.SharedMemory] = []

View File

@ -5,7 +5,6 @@ import logging
import os
import threading
from enum import Enum
from multiprocessing.synchronize import Event as MpEvent
from pathlib import Path
from frigate.config import FrigateConfig
@ -22,7 +21,7 @@ class EventCleanupType(str, Enum):
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")
self.config = config
self.stop_event = stop_event

View File

@ -1,7 +1,6 @@
import logging
import threading
from multiprocessing import Queue
from multiprocessing.synchronize import Event as MpEvent
from typing import Dict
from frigate.comms.events_updater import EventEndPublisher, EventUpdateSubscriber
@ -52,7 +51,7 @@ class EventProcessor(threading.Thread):
self,
config: FrigateConfig,
timeline_queue: Queue,
stop_event: MpEvent,
stop_event: threading.Event,
):
super().__init__(name="event_processor")
self.config = config

View File

@ -6,7 +6,6 @@ import os
import queue
import threading
from collections import Counter, defaultdict
from multiprocessing.synchronize import Event as MpEvent
from statistics import median
from typing import Callable
@ -919,13 +918,13 @@ class TrackedObjectProcessor(threading.Thread):
dispatcher: Dispatcher,
tracked_objects_queue,
ptz_autotracker_thread,
stop_event,
stop_event: threading.Event,
):
super().__init__(name="detected_frames_processor")
self.config = config
self.dispatcher = dispatcher
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.frame_manager = SharedMemoryFrameManager()
self.last_motion_detected: dict[str, float] = {}

View File

@ -4,7 +4,6 @@ import datetime
import glob
import logging
import math
import multiprocessing as mp
import os
import queue
import subprocess as sp
@ -114,7 +113,7 @@ class FFMpegConverter(threading.Thread):
self,
ffmpeg: FfmpegConfig,
input_queue: queue.Queue,
stop_event: mp.Event,
stop_event: threading.Event,
in_width: int,
in_height: int,
out_width: int,
@ -232,7 +231,7 @@ class BroadcastThread(threading.Thread):
camera: str,
converter: FFMpegConverter,
websocket_server,
stop_event: mp.Event,
stop_event: threading.Event,
):
super().__init__()
self.camera = camera
@ -269,7 +268,7 @@ class BirdsEyeFrameManager:
self,
config: FrigateConfig,
frame_manager: SharedMemoryFrameManager,
stop_event: mp.Event,
stop_event: threading.Event,
):
self.config = config
self.mode = config.birdseye.mode
@ -718,7 +717,7 @@ class Birdseye:
def __init__(
self,
config: FrigateConfig,
stop_event: mp.Event,
stop_event: threading.Event,
websocket_server,
) -> None:
self.config = config

View File

@ -1,7 +1,6 @@
"""Handle outputting individual cameras via jsmpeg."""
import logging
import multiprocessing as mp
import queue
import subprocess as sp
import threading
@ -17,7 +16,7 @@ class FFMpegConverter(threading.Thread):
camera: str,
ffmpeg: FfmpegConfig,
input_queue: queue.Queue,
stop_event: mp.Event,
stop_event: threading.Event,
in_width: int,
in_height: int,
out_width: int,
@ -99,7 +98,7 @@ class BroadcastThread(threading.Thread):
camera: str,
converter: FFMpegConverter,
websocket_server,
stop_event: mp.Event,
stop_event: threading.Event,
):
super().__init__()
self.camera = camera
@ -133,7 +132,7 @@ class BroadcastThread(threading.Thread):
class JsmpegCamera:
def __init__(
self, config: CameraConfig, stop_event: mp.Event, websocket_server
self, config: CameraConfig, stop_event: threading.Event, websocket_server
) -> None:
self.config = config
self.input = queue.Queue(maxsize=config.detect.fps)

View File

@ -8,7 +8,6 @@ import threading
import time
from collections import deque
from functools import partial
from multiprocessing.synchronize import Event as MpEvent
import cv2
import numpy as np
@ -147,7 +146,7 @@ class PtzAutoTrackerThread(threading.Thread):
onvif: OnvifController,
ptz_metrics: dict[str, PTZMetrics],
dispatcher: Dispatcher,
stop_event: MpEvent,
stop_event: threading.Event,
) -> None:
super().__init__(name="ptz_autotracker")
self.ptz_autotracker = PtzAutoTracker(
@ -180,7 +179,7 @@ class PtzAutoTracker:
onvif: OnvifController,
ptz_metrics: PTZMetrics,
dispatcher: Dispatcher,
stop_event: MpEvent,
stop_event: threading.Event,
) -> None:
self.config = config
self.onvif = onvif

View File

@ -5,7 +5,6 @@ import itertools
import logging
import os
import threading
from multiprocessing.synchronize import Event as MpEvent
from pathlib import Path
from playhouse.sqlite_ext import SqliteExtDatabase
@ -22,7 +21,7 @@ logger = logging.getLogger(__name__)
class RecordingCleanup(threading.Thread):
"""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")
self.config = config
self.stop_event = stop_event

View File

@ -5,7 +5,6 @@ import json
import logging
import threading
import time
from multiprocessing.synchronize import Event as MpEvent
from typing import Optional
from frigate.comms.inter_process import InterProcessRequestor
@ -25,7 +24,7 @@ class StatsEmitter(threading.Thread):
self,
config: FrigateConfig,
stats_tracking: StatsTrackingTypes,
stop_event: MpEvent,
stop_event: threading.Event,
):
super().__init__(name="frigate_stats_emitter")
self.config = config

View File

@ -21,7 +21,7 @@ bandwidth_equation = Recordings.segment_size / (
class StorageMaintainer(threading.Thread):
"""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")
self.config = config
self.stop_event = stop_event

View File

@ -4,7 +4,6 @@ import logging
import queue
import threading
from multiprocessing import Queue
from multiprocessing.synchronize import Event as MpEvent
from frigate.config import FrigateConfig
from frigate.events.maintainer import EventTypeEnum
@ -21,7 +20,7 @@ class TimelineProcessor(threading.Thread):
self,
config: FrigateConfig,
queue: Queue,
stop_event: MpEvent,
stop_event: threading.Event,
) -> None:
super().__init__(name="timeline_processor")
self.config = config

View File

@ -1,7 +1,6 @@
import datetime
import logging
import threading
from multiprocessing.synchronize import Event as MpEvent
from frigate.object_detection import ObjectDetectProcess
from frigate.util.services import restart_frigate
@ -10,7 +9,9 @@ logger = logging.getLogger(__name__)
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")
self.detectors = detectors
self.stop_event = stop_event