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