From cc2d81c9add9f09567ed5f9f612dff8e07027bcf Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 16 Jan 2026 16:33:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B9=B6=E8=A1=8COCR=E6=97=B6=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E6=B8=85=E7=90=86=E6=88=AA=E5=9B=BE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在并行记录映射表时不清理截图文件,避免主线程OCR时文件不存在 - 通过检查 _screenshot_ready_for_ocr 标志来判断是否在并行处理中 --- .../reservation/douyin_reservation_handler.py | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/douyin/reservation/douyin_reservation_handler.py b/douyin/reservation/douyin_reservation_handler.py index d775dbf..0ebfbf8 100644 --- a/douyin/reservation/douyin_reservation_handler.py +++ b/douyin/reservation/douyin_reservation_handler.py @@ -225,28 +225,31 @@ class ReservationHandler: room_pos = int(getattr(analyser, "room_pos", 0) or 0) # 在记录映射表前清理旧截图文件,避免复用过期的截图 - try: - import path_config - import os + # 但在并行处理时不清理,因为主线程还在使用截图文件 + is_parallel_recording = getattr(analyser, "_screenshot_ready_for_ocr", False) + if not is_parallel_recording: + try: + import path_config + import os - pic_path = path_config.get_screenshot_path() - if os.path.exists(pic_path): - os.remove(pic_path) + pic_path = path_config.get_screenshot_path() + if os.path.exists(pic_path): + os.remove(pic_path) + analyser._log_kv( + "预约", + "[预约] 清理旧截图文件,避免复用过期截图", + room_pos=room_pos, + path=pic_path, + log_type="SCREENSHOT", + ) + except Exception as e: analyser._log_kv( "预约", - "[预约] 清理旧截图文件,避免复用过期截图", + f"[预约] 清理旧截图文件失败 - {str(e)}", room_pos=room_pos, - path=pic_path, - log_type="SCREENSHOT", + level="WARNING", + error=str(e), ) - except Exception as e: - analyser._log_kv( - "预约", - f"[预约] 清理旧截图文件失败 - {str(e)}", - room_pos=room_pos, - level="WARNING", - error=str(e), - ) # 检查是否已经为当前直播间识别过标题,避免重复截图和OCR identified_positions = getattr(