From a2825427728fa20d73162f7e7b888158b516e171 Mon Sep 17 00:00:00 2001 From: zqc <835569504@qq.com> Date: Thu, 5 Feb 2026 14:39:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BB=E6=89=BE=E4=B8=8B=E4=B8=80=E5=88=86?= =?UTF-8?q?=E7=89=87=E7=AD=89=E5=BE=85=E6=97=B6=E9=97=B4=E5=81=9A=E7=BB=86?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hls_service_ws_kadian.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/hls_service_ws_kadian.py b/hls_service_ws_kadian.py index df67185..4f9e4a9 100644 --- a/hls_service_ws_kadian.py +++ b/hls_service_ws_kadian.py @@ -194,12 +194,18 @@ class HLSFrameProcessor(threading.Thread): # 处理初始分片 self.process_segment_with_rate_control(initial_segment) + # 连续检测失败计数器 + consecutive_failures = 0 + while not self.stop_event.is_set(): try: # 查找下一个分片 next_segment = self.find_next_segment() if next_segment is not None: + # 重置连续失败计数器 + consecutive_failures = 0 + # 处理下一个分片 logger.info(f"[INFO] Starting to process TS segment: {next_segment}") self.current_segment_num += 1 @@ -208,9 +214,18 @@ class HLSFrameProcessor(threading.Thread): logger.info(f"[INFO] Finished processing segment {self.current_segment_num}") else: - # 下一个分片不存在,等待 - logger.warning(f"[WARN] No next segment found, waiting...") - time.sleep(0.5) + # 下一个分片不存在,根据连续失败次数调整等待时间 + consecutive_failures += 1 + + if consecutive_failures <= 10: + sleep_time = 0.02 # 前10次失败,等待0.02秒 + elif consecutive_failures <= 20: + sleep_time = 0.05 # 继续5次失败,等待0.05秒 + else: + sleep_time = 0.5 # 超过15次失败,等待0.5秒 + + logger.warning(f"[WARN] No next segment found (failures: {consecutive_failures}), waiting {sleep_time}s...") + time.sleep(sleep_time) except Exception as e: logger.error(f"[ERROR] HLSFrameProcessor loop error: {e}")