下载进程和业务进程分开控制

This commit is contained in:
zqc
2026-02-28 12:22:34 +08:00
parent 61f315f6c7
commit f0ec2cb855
2 changed files with 23 additions and 8 deletions

View File

@@ -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 # 凌晨轮换时间

View File

@@ -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