下载进程和业务进程分开控制
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user