From f0ec2cb8551a559a912220948168fe6fdabb33e4 Mon Sep 17 00:00:00 2001 From: zqc <835569504@qq.com> Date: Sat, 28 Feb 2026 12:22:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E8=BF=9B=E7=A8=8B=E5=92=8C?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E8=BF=9B=E7=A8=8B=E5=88=86=E5=BC=80=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 1 + main_start.py | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/config.yaml b/config.yaml index 18dc62b..cf6bcf8 100644 --- a/config.yaml +++ b/config.yaml @@ -33,6 +33,7 @@ database: # 服务组配置:每个组有独立的 WebSocket 和算法类型 # debug_mode: True=前台运行(适合PyCharm调试),False=后台运行(适合生产部署) debug_mode: true +downloader_debug_mode: false # 下载进程调试模式 alert_push_url: "http://123.57.151.210:10000/picenter/websocket/test/process" hls_root_path: "D:/ProjectDoc/Police/data/hls" hls_downloader_daily_rotate_hour: 3 # 凌晨轮换时间 diff --git a/main_start.py b/main_start.py index f7a607f..00a843a 100644 --- a/main_start.py +++ b/main_start.py @@ -36,8 +36,19 @@ def load_debug_mode(config_path: str = "config.yaml") -> bool: return False +def load_downloader_debug_mode(config_path: str = "config.yaml") -> bool: + """从配置文件读取下载器调试模式""" + try: + with open(config_path, "r", encoding="utf-8") as f: + cfg = yaml.safe_load(f) + return cfg.get("downloader_debug_mode", False) + except Exception: + return False + + # 调试模式:从配置文件读取 DEBUG_MODE = load_debug_mode() +DOWNLOADER_DEBUG_MODE = load_downloader_debug_mode() def load_service_groups_from_yaml(config_path: str = "config.yaml") -> List[dict]: @@ -220,7 +231,7 @@ def start_hls_downloader(camera: dict, hls_config: dict) -> Optional[subprocess. logger.info(f"[INFO] Starting HLS downloader for camera '{camera_name}' (index: {index_code})") - if DEBUG_MODE: + if DOWNLOADER_DEBUG_MODE: process = subprocess.Popen(cmd) else: process = subprocess.Popen(cmd, start_new_session=True) @@ -288,13 +299,16 @@ def start_service(): logger.info(f"[INFO] Started {started_count}/{len(service_groups)} service groups") logger.info(f"[INFO] Started {downloader_count} HLS downloaders") - # DEBUG_MODE=True 时,主进程等待所有子进程 - if DEBUG_MODE: - all_processes = processes + downloader_processes - if all_processes: - logger.info("[DEBUG] Running in foreground mode, waiting for child processes...") - for process, name in all_processes: - process.wait() + # 根据各自的调试模式决定是否等待子进程 + if DEBUG_MODE and processes: + logger.info("[DEBUG] Waiting for service processes...") + for process, name in processes: + process.wait() + + if DOWNLOADER_DEBUG_MODE and downloader_processes: + logger.info("[DEBUG] Waiting for downloader processes...") + for process, name in downloader_processes: + process.wait() return started_count > 0