From 746f24636a97aea24bb5539d83ce2ff719405da4 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 17 Jan 2026 23:50:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E7=BA=A6:=20=E5=9C=A8seek=5Freservati?= =?UTF-8?q?on=5Froom=E4=B8=AD=E6=B7=BB=E5=8A=A0=E6=80=BB=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E4=B8=8A=E9=99=9030=E7=A7=92=EF=BC=8C=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E5=8D=A1=E6=AD=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/douyin_reservation_handler.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/douyin/reservation/douyin_reservation_handler.py b/douyin/reservation/douyin_reservation_handler.py index c202f19..472e2a3 100644 --- a/douyin/reservation/douyin_reservation_handler.py +++ b/douyin/reservation/douyin_reservation_handler.py @@ -524,6 +524,10 @@ class ReservationHandler: target_room_title = str(item.get("room_title") or "").strip() target_room_title_raw = str(item.get("room_title_raw") or "").strip() + # 记录开始时间,防止总时间过长卡死 + seek_start_time = time.time() + max_seek_duration = 30.0 # 最大30秒 + # 输出目标直播间的位置和标题信息 try: analyser._log_kv( # type: ignore[attr-defined] @@ -627,6 +631,18 @@ class ReservationHandler: except Exception: pass return False + # 检查总时间是否超过上限 + if time.time() - seek_start_time > max_seek_duration: + try: + analyser._log_kv( + operation_type, + f"[{operation_type}] _seek_reservation_room:总时间超过上限,停止回退", + elapsed_seconds=time.time() - seek_start_time, + max_duration=max_seek_duration, + ) + except Exception: + pass + return False elif pos_diff < 0: # 目标在上方(target_pos < cur_pos),需要向上回退(减少 room_pos) back_times = min(abs(pos_diff), max_back) if max_back > 0 else abs(pos_diff) @@ -679,6 +695,18 @@ class ReservationHandler: ) except Exception: pass + # 检查总时间是否超过上限 + if time.time() - seek_start_time > max_seek_duration: + try: + analyser._log_kv( + operation_type, + f"[{operation_type}] _seek_reservation_room:总时间超过上限,停止回退", + elapsed_seconds=time.time() - seek_start_time, + max_duration=max_seek_duration, + ) + except Exception: + pass + return False # 回退时设置标志,跳过记录标题(因为之前已经记录过了) try: analyser._skip_record_title_during_seek = True