diff --git a/SCREENSHOT_PERFORMANCE_DIAGNOSIS.md b/SCREENSHOT_PERFORMANCE_DIAGNOSIS.md index 6824bf2..f39a51c 100644 --- a/SCREENSHOT_PERFORMANCE_DIAGNOSIS.md +++ b/SCREENSHOT_PERFORMANCE_DIAGNOSIS.md @@ -215,3 +215,4 @@ python test_adb_screenshot_timing.py - `test_adb_screenshot_timing.py` - ADB 基准测试脚本 + diff --git a/STREAMING_SCREENSHOT_COMPLETELY_DISABLED.md b/STREAMING_SCREENSHOT_COMPLETELY_DISABLED.md index ddf1a85..50c9ec4 100644 --- a/STREAMING_SCREENSHOT_COMPLETELY_DISABLED.md +++ b/STREAMING_SCREENSHOT_COMPLETELY_DISABLED.md @@ -114,3 +114,4 @@ def get_screenshot(self, device_id: str, force: bool = False) -> bool: + diff --git a/STREAMING_SCREENSHOT_DISABLED.md b/STREAMING_SCREENSHOT_DISABLED.md index 3bdf360..31440d8 100644 --- a/STREAMING_SCREENSHOT_DISABLED.md +++ b/STREAMING_SCREENSHOT_DISABLED.md @@ -71,3 +71,4 @@ def get_screenshot(self, device_id, path="pic", use_service: bool = True) -> boo + diff --git a/check_screenshot.py b/check_screenshot.py index 8e36176..db81aa3 100644 --- a/check_screenshot.py +++ b/check_screenshot.py @@ -58,3 +58,4 @@ if __name__ == "__main__": + diff --git a/check_screenshot_service_status.py b/check_screenshot_service_status.py index a93a299..15b044c 100644 --- a/check_screenshot_service_status.py +++ b/check_screenshot_service_status.py @@ -70,3 +70,4 @@ if __name__ == '__main__': + diff --git a/docs/scrcpy_手动安装指南.md b/docs/scrcpy_手动安装指南.md index e9b9091..6502a7e 100644 --- a/docs/scrcpy_手动安装指南.md +++ b/docs/scrcpy_手动安装指南.md @@ -215,3 +215,4 @@ scrcpy --bit-rate=2M + diff --git a/docs/多线程优化实现总结.md b/docs/多线程优化实现总结.md index 409f6c4..4f07e85 100644 --- a/docs/多线程优化实现总结.md +++ b/docs/多线程优化实现总结.md @@ -209,3 +209,4 @@ python tools/check_system_config.py + diff --git a/docs/多线程截图优化说明.md b/docs/多线程截图优化说明.md index 1490306..a98feab 100644 --- a/docs/多线程截图优化说明.md +++ b/docs/多线程截图优化说明.md @@ -227,3 +227,4 @@ python tools/check_system_config.py + diff --git a/docs/截图服务日志说明.md b/docs/截图服务日志说明.md index a0f9977..b12545f 100644 --- a/docs/截图服务日志说明.md +++ b/docs/截图服务日志说明.md @@ -286,3 +286,4 @@ grep "缓存命中" logs/unified_*.log + diff --git a/docs/日志轮转功能说明.md b/docs/日志轮转功能说明.md index f56e4f9..455f644 100644 --- a/docs/日志轮转功能说明.md +++ b/docs/日志轮转功能说明.md @@ -197,3 +197,4 @@ unified_2024-01-15.1.log.gz # 压缩后的文件 + diff --git a/docs/测试验证指南.md b/docs/测试验证指南.md index e5d9220..9ffb719 100644 --- a/docs/测试验证指南.md +++ b/docs/测试验证指南.md @@ -189,3 +189,4 @@ print(f"最后截图时间: {info['last_screenshot_time']}") + diff --git a/douyin/core/fudai_modules/base_interface.py b/douyin/core/fudai_modules/base_interface.py index 5a02dfa..5c13f83 100644 --- a/douyin/core/fudai_modules/base_interface.py +++ b/douyin/core/fudai_modules/base_interface.py @@ -119,5 +119,6 @@ class BaseFudaiMixin: + diff --git a/douyin/core/fudai_modules/fudai_room_utils.py b/douyin/core/fudai_modules/fudai_room_utils.py index 76034f6..f38d62a 100644 --- a/douyin/core/fudai_modules/fudai_room_utils.py +++ b/douyin/core/fudai_modules/fudai_room_utils.py @@ -93,5 +93,6 @@ class RoomUtilsMixin: + diff --git a/douyin/core/state/reservations.json b/douyin/core/state/reservations.json index f9d8e8d..6b9fbae 100644 --- a/douyin/core/state/reservations.json +++ b/douyin/core/state/reservations.json @@ -1,5 +1,5 @@ { - "updated_ts": 1767289069.9178874, + "updated_ts": 1767290732.5810602, "reason": "startup_clear", "room_pos": 0, "current_room_title": "", diff --git a/douyin/detection/core/__init__.py b/douyin/detection/core/__init__.py index aab24f1..46a6672 100644 --- a/douyin/detection/core/__init__.py +++ b/douyin/detection/core/__init__.py @@ -65,5 +65,6 @@ __all__ = [ + diff --git a/douyin/fudai/core/MODULARIZATION_PLAN.md b/douyin/fudai/core/MODULARIZATION_PLAN.md index e8e0fdc..d0f5c73 100644 --- a/douyin/fudai/core/MODULARIZATION_PLAN.md +++ b/douyin/fudai/core/MODULARIZATION_PLAN.md @@ -106,5 +106,6 @@ + diff --git a/douyin/fudai/finder/__init__.py b/douyin/fudai/finder/__init__.py index 22363ae..4a13b5c 100644 --- a/douyin/fudai/finder/__init__.py +++ b/douyin/fudai/finder/__init__.py @@ -70,5 +70,6 @@ __all__ = [ + diff --git a/douyin/logging/action_tracker.py b/douyin/logging/action_tracker.py index da05b01..92a3a94 100644 --- a/douyin/logging/action_tracker.py +++ b/douyin/logging/action_tracker.py @@ -61,5 +61,6 @@ __all__ = ["track_action"] + diff --git a/douyin/reservation/core/__init__.py b/douyin/reservation/core/__init__.py index b03db7a..9781516 100644 --- a/douyin/reservation/core/__init__.py +++ b/douyin/reservation/core/__init__.py @@ -80,5 +80,6 @@ __all__ = [ + diff --git a/douyin_guaji.code-workspace b/douyin_guaji.code-workspace index 513c693..dbe2735 100644 --- a/douyin_guaji.code-workspace +++ b/douyin_guaji.code-workspace @@ -83,5 +83,6 @@ + diff --git a/gui/components/__init__.py b/gui/components/__init__.py index 2a12c56..3d30fd1 100644 --- a/gui/components/__init__.py +++ b/gui/components/__init__.py @@ -50,5 +50,6 @@ + diff --git a/gui/components/config_manager.py b/gui/components/config_manager.py index 2c3df7d..10f39ce 100644 --- a/gui/components/config_manager.py +++ b/gui/components/config_manager.py @@ -90,5 +90,6 @@ def save_ui_to_config( + diff --git a/gui/components/device_selector.py b/gui/components/device_selector.py index 47986b1..a281db7 100644 --- a/gui/components/device_selector.py +++ b/gui/components/device_selector.py @@ -100,5 +100,6 @@ def create_device_selector( + diff --git a/gui/components/image_viewer.py b/gui/components/image_viewer.py index 17f159f..e7cdf3f 100644 --- a/gui/components/image_viewer.py +++ b/gui/components/image_viewer.py @@ -86,5 +86,6 @@ def create_image_viewer( + diff --git a/gui/components/log_color_config_fixed.py b/gui/components/log_color_config_fixed.py index 68a8bc1..0d8d0b7 100644 --- a/gui/components/log_color_config_fixed.py +++ b/gui/components/log_color_config_fixed.py @@ -211,3 +211,4 @@ def apply_operation_color( + diff --git a/gui/components/main_window.py b/gui/components/main_window.py index 6f1de7f..2d9240a 100644 --- a/gui/components/main_window.py +++ b/gui/components/main_window.py @@ -82,5 +82,6 @@ def create_main_window( + diff --git a/gui/components/ocr_panel.py b/gui/components/ocr_panel.py index 8bdf817..c000d13 100644 --- a/gui/components/ocr_panel.py +++ b/gui/components/ocr_panel.py @@ -83,5 +83,6 @@ def create_ocr_panel( + diff --git a/gui/web_components/__init__.py b/gui/web_components/__init__.py index af9912b..313a249 100644 --- a/gui/web_components/__init__.py +++ b/gui/web_components/__init__.py @@ -50,5 +50,6 @@ + diff --git a/gui/web_components/proc_runner.py b/gui/web_components/proc_runner.py index 80e1025..1178dac 100644 --- a/gui/web_components/proc_runner.py +++ b/gui/web_components/proc_runner.py @@ -58,5 +58,6 @@ __all__ = ["ProcRunner"] + diff --git a/install_scrcpy.bat b/install_scrcpy.bat index a211068..c4a481c 100644 --- a/install_scrcpy.bat +++ b/install_scrcpy.bat @@ -129,3 +129,4 @@ goto :eof + diff --git a/manage_logs.py b/manage_logs.py index 28653ae..eae5596 100644 --- a/manage_logs.py +++ b/manage_logs.py @@ -259,3 +259,4 @@ if __name__ == "__main__": + diff --git a/operations/ocr_operations.py b/operations/ocr_operations.py index 40850f9..324142d 100644 --- a/operations/ocr_operations.py +++ b/operations/ocr_operations.py @@ -180,29 +180,38 @@ def _ensure_ocr(): def analyse_pic_word(picname, change_color=0, pic_path=None): """文字OCR识别(向后兼容接口)""" - # 这里应该实现实际的OCR文字识别逻辑 - # 暂时从原文件导入以保持功能 + # 使用全局复用的 underlying_operations 实例,避免每次调用都初始化 OCR(耗时) from Underlying_Operations import underlying_operations - instance = underlying_operations() - return instance.analyse_pic_word(picname, change_color, pic_path) + global _UNDERLYING_OPS_SINGLETON # type: ignore[name-defined] + try: + _UNDERLYING_OPS_SINGLETON # type: ignore[name-defined] + except NameError: + _UNDERLYING_OPS_SINGLETON = underlying_operations() + return _UNDERLYING_OPS_SINGLETON.analyse_pic_word(picname, change_color, pic_path) def analyse_pic_digits(picname, change_color=1, pic_path=None): """数字OCR识别(向后兼容接口)""" - # 这里应该实现实际的OCR数字识别逻辑 - # 暂时从原文件导入以保持功能 + # 使用全局复用的 underlying_operations 实例,避免每次调用都初始化 OCR(耗时) from Underlying_Operations import underlying_operations - instance = underlying_operations() - return instance.analyse_pic_digits(picname, change_color, pic_path) + global _UNDERLYING_OPS_SINGLETON # type: ignore[name-defined] + try: + _UNDERLYING_OPS_SINGLETON # type: ignore[name-defined] + except NameError: + _UNDERLYING_OPS_SINGLETON = underlying_operations() + return _UNDERLYING_OPS_SINGLETON.analyse_pic_digits(picname, change_color, pic_path) def extract_ocr_content(content=[], return_confidence=False): """提取OCR内容(向后兼容接口)""" - # 这里应该实现实际的OCR内容提取逻辑 - # 暂时从原文件导入以保持功能 + # 使用全局复用的 underlying_operations 实例 from Underlying_Operations import underlying_operations - instance = underlying_operations() - return instance.extract_ocr_content(content, return_confidence) + global _UNDERLYING_OPS_SINGLETON # type: ignore[name-defined] + try: + _UNDERLYING_OPS_SINGLETON # type: ignore[name-defined] + except NameError: + _UNDERLYING_OPS_SINGLETON = underlying_operations() + return _UNDERLYING_OPS_SINGLETON.extract_ocr_content(content, return_confidence) __all__ = [ diff --git a/operations/screenshot_operations.py b/operations/screenshot_operations.py index fce36b6..2cd70f1 100644 --- a/operations/screenshot_operations.py +++ b/operations/screenshot_operations.py @@ -192,17 +192,26 @@ class ScreenshotOperations: print(f"[截图] exec-out 流式读取超时") raise if _valid_png(tmp_file): - # 使用安全的文件替换函数 + # 使用安全的文件替换函数并二次验证目标文件,避免写入截断导致后续读取失败 if _safe_replace_file(tmp_file, out_file): - _mirror_screenshot_to_external(out_file) - elapsed = (time.time() - direct_start) * 1000 - print(f"[{timetag}] [截图] [OK] 获取屏幕截图成功 (exec-out,耗时: {elapsed:.0f}ms)") - return True + # 目标文件替换后再验证一次,确保不是零字节或截断 + if _valid_png(out_file): + _mirror_screenshot_to_external(out_file) + elapsed = (time.time() - direct_start) * 1000 + print(f"[{timetag}] [截图] [OK] 获取屏幕截图成功 (exec-out,耗时: {elapsed:.0f}ms)") + return True + else: + # 替换后目标文件不完整,记录并尝试回退到 pull + print(f"[{timetag}] [截图] 警告:替换后目标文件不完整,回退到 pull") + try: + if os.path.exists(out_file): + os.remove(out_file) + except Exception: + pass + # 不立即返回,继续尝试回退方案 else: - # 如果替换失败,但临时文件有效,仍然返回成功 - # 后续代码可以读取临时文件或重试 - print(f"[截图] 文件替换失败,但截图已保存到临时文件,将重试") - # 不立即返回,继续尝试回退方案 + # 如果替换失败,但临时文件有效,记录并尝试回退方案 + print(f"[{timetag}] [截图] 文件替换失败,但截图已保存到临时文件,将尝试回退方案") except subprocess.TimeoutExpired: # 超时异常,记录并继续重试 print(f"[截图] exec-out 超时,尝试重试或回退方案") diff --git a/operations/screenshot_service.py b/operations/screenshot_service.py index c0ad42c..3eb16d6 100644 --- a/operations/screenshot_service.py +++ b/operations/screenshot_service.py @@ -1,10 +1,9 @@ -"""operations.screenshot_service -简洁、类型良好的后台截图服务实现。 +"""后台截图服务:持续截图,主流程直接读取最新截图 功能: -- 单例后台线程持续截图(避免主流程等待) -- 缓存验证与直接截图回退 -- 对外导出 get_optimal_workers 工具函数 +1. 后台持续截图,避免主流程等待 +2. 截图缓存机制,减少重复截图 +3. 智能线程数配置,根据CPU核心数自动调整 """ from __future__ import annotations @@ -12,94 +11,45 @@ from __future__ import annotations import os import threading import time -from typing import Optional, Dict, Any +from typing import Optional from datetime import datetime - -from operations.screenshot_operations import ScreenshotOperations -import json import path_config - - -def _streaming_enabled() -> bool: - """从 config.json 动态读取 enable_streaming_screenshot(默认 True)。""" - try: - # 如果环境变量强制禁用流式截图,则立即返回 False(便于调试/临时关闭) - if os.environ.get("DISABLE_STREAMING_SCREENSHOT", "0") == "1": - return False - - cfg_path = path_config.get_config_path() - if cfg_path and os.path.exists(cfg_path): - with open(cfg_path, "r", encoding="utf-8") as f: - cfg = json.load(f) - # 默认行为:如果配置中指定,则返回配置值;否则默认禁用流式截图以保证直接截图优先 - return bool(cfg.get("enable_streaming_screenshot", False)) - except Exception: - pass - # 如果读取配置失败,默认禁用流式截图以避免主流程被后台服务等待阻塞 - return False +from operations.screenshot_operations import ScreenshotOperations class ScreenshotService: - """后台截图服务(单例)""" + """后台截图服务:持续截图,避免主流程等待""" - _instance: Optional["ScreenshotService"] = None + _instance: Optional['ScreenshotService'] = None _lock = threading.Lock() - def __init__(self) -> None: + def __init__(self): self._running: bool = False self._thread: Optional[threading.Thread] = None self._screenshot_ops: ScreenshotOperations = ScreenshotOperations() self._current_device_id: Optional[str] = None - self._last_screenshot_time: float = time.time() - 10.0 - self._screenshot_interval: float = 1.5 - self._cache_valid_duration: float = 2.0 + # 初始化为过去时间,避免第一次请求时出现异常行为 + self._last_screenshot_time = time.time() - 10.0 + self._screenshot_interval = 3.5 + self._cache_valid_duration = 4.0 self._screenshot_path: Optional[str] = None - self._last_success: bool = False - # 缓存配置读取结果以避免每次调用都读取文件并频繁打印相同日志 - self._streaming_enabled_cached: Optional[bool] = None - self._last_streaming_state_log_ts: float = 0.0 - self._last_streaming_check_ts: float = 0.0 - - def _check_streaming_enabled(self) -> bool: - """内部缓存检查配置,避免每次调用都读取文件。短时间内重复调用会复用缓存。""" - now = time.time() - # 刷新间隔:3 秒 - try: - if self._streaming_enabled_cached is None or (now - self._last_streaming_check_ts) > 3.0: - try: - enabled = _streaming_enabled() - except Exception: - enabled = True - self._streaming_enabled_cached = bool(enabled) - self._last_streaming_check_ts = now - except Exception: - # 任何异常时默认启用以不阻塞主流程 - self._streaming_enabled_cached = True - self._last_streaming_check_ts = now - return bool(self._streaming_enabled_cached) + self._last_success = False @classmethod - def get_instance(cls) -> "ScreenshotService": + def get_instance(cls) -> 'ScreenshotService': if cls._instance is None: with cls._lock: if cls._instance is None: cls._instance = cls() + # 类型检查确保:此处在返回前 cls._instance 已被初始化 + assert cls._instance is not None return cls._instance - def start(self, device_id: str, interval: float = 1.5) -> None: - """启动后台截图服务""" - if not self._check_streaming_enabled(): - timetag = datetime.now().strftime("%H:%M:%S") - # 仅在状态变化或首次检测时打印日志,避免重复冗余信息 - now = time.time() - if now - self._last_streaming_state_log_ts > 30: - print(f"[{timetag}] [截图服务] 流式后台截图已被禁用(config),忽略 start() 请求") - self._last_streaming_state_log_ts = now - return + def start(self, device_id: str, interval: float = 1.5): with self._lock: - if self._running and self._current_device_id == device_id: - return if self._running: + if self._current_device_id == device_id: + return self.stop() self._current_device_id = device_id @@ -108,26 +58,31 @@ class ScreenshotService: try: self._screenshot_path = path_config.get_screenshot_path() - except Exception: + except (ImportError, AttributeError, OSError): self._screenshot_path = os.path.join("pic", "screenshot.png") - self._thread = threading.Thread(target=self._screenshot_loop, daemon=True, name="ScreenshotService") + self._thread = threading.Thread( + target=self._screenshot_loop, daemon=True, name="ScreenshotService" + ) self._thread.start() self._last_screenshot_time = time.time() - self._cache_valid_duration - 1.0 timetag = datetime.now().strftime("%H:%M:%S") - print(f"[{timetag}] [截图服务] 已启动,device={device_id}, interval={self._screenshot_interval}s") - - def stop(self) -> None: + print(f"[{timetag}] [截图服务] 已启动后台截图服务,设备: {device_id}, 间隔: {interval}秒") + + def stop(self): + """停止后台截图服务""" with self._lock: if not self._running: return self._running = False + if self._thread and self._thread.is_alive(): self._thread.join(timeout=2.0) timetag = datetime.now().strftime("%H:%M:%S") - print(f"[{timetag}] [截图服务] 已停止") - - def _screenshot_loop(self) -> None: + print(f"[{timetag}] [截图服务] 已停止后台截图服务") + + def _screenshot_loop(self): + """后台截图循环""" loop_count = 0 while self._running: try: @@ -135,84 +90,213 @@ class ScreenshotService: if not device_id: time.sleep(0.1) continue - + loop_count += 1 timetag = datetime.now().strftime("%H:%M:%S") - start = time.time() - try: - success = self._screenshot_ops.get_screenshot(device_id, use_service=False) # type: ignore[arg-type] - except Exception: - success = False - elapsed_ms = (time.time() - start) * 1000 - - if success and self._screenshot_path and os.path.exists(self._screenshot_path): - try: - size = os.path.getsize(self._screenshot_path) - if size >= 1024: - with open(self._screenshot_path, "rb") as f: - header = f.read(4) - if header == b"\x89PNG": - self._last_screenshot_time = time.time() - self._last_success = True - print(f"[{timetag}] [截图服务] 完成 #{loop_count},{elapsed_ms:.0f}ms, {size}B") - else: - self._last_success = False - else: + screenshot_start = time.time() + + # 执行截图(禁用服务模式,避免递归) + success = self._screenshot_ops.get_screenshot(device_id, use_service=False) # type: ignore[arg-type] + + screenshot_elapsed = (time.time() - screenshot_start) * 1000 + if success: + # 验证文件完整性后再更新时间戳(避免读取到不完整的文件) + if self._screenshot_path and os.path.exists(self._screenshot_path): + try: + file_size = os.path.getsize(self._screenshot_path) + if file_size >= 1024: + with open(self._screenshot_path, 'rb') as f: + header = f.read(4) + if header == b'\x89PNG': + self._last_screenshot_time = time.time() + self._last_success = True + print(f"[{timetag}] [截图服务] 后台截图完成 #{loop_count},耗时: {screenshot_elapsed:.0f}ms,文件大小: {file_size/1024:.1f}KB") + else: + self._last_success = False + print(f"[{timetag}] [截图服务] 后台截图文件格式错误 #{loop_count},耗时: {screenshot_elapsed:.0f}ms") + else: + self._last_success = False + print(f"[{timetag}] [截图服务] 后台截图文件太小 #{loop_count} ({file_size}B),耗时: {screenshot_elapsed:.0f}ms") + except (OSError, IOError, ValueError) as e: self._last_success = False - except Exception: + print(f"[{timetag}] [截图服务] 后台截图文件验证失败 #{loop_count}: {e},耗时: {screenshot_elapsed:.0f}ms") + else: self._last_success = False + print(f"[{timetag}] [截图服务] 后台截图文件不存在 #{loop_count},耗时: {screenshot_elapsed:.0f}ms") else: self._last_success = False - - wait = max(0.5, self._screenshot_interval - elapsed_ms / 1000) - time.sleep(wait) - except Exception: - time.sleep(1.0) - - def get_screenshot(self, device_id: str, force: bool = False) -> bool: - """尝试从缓存返回截图状态;否则执行直接截图回退""" - if not self._check_streaming_enabled(): - # 如果配置关闭但后台线程仍在运行,尝试停止它(仅在需要时) - if self._running: + print(f"[{timetag}] [截图服务] 后台截图失败 #{loop_count},耗时: {screenshot_elapsed:.0f}ms") + + # 等待间隔时间,确保不小于0.5秒 + remaining_interval = max(0.5, self._screenshot_interval - screenshot_elapsed / 1000) + time.sleep(remaining_interval) + except Exception as e: try: - self.stop() + timetag = datetime.now().strftime("%H:%M:%S") + print(f"[{timetag}] [截图服务] 后台截图异常: {e}") + import traceback + traceback.print_exc() except Exception: pass - timetag = datetime.now().strftime("%H:%M:%S") - now = time.time() - # 节流:30 秒内只打印一次此日志,避免重复输出 - if now - self._last_streaming_state_log_ts > 30: - print(f"[{timetag}] [截图服务] 流式后台截图被禁用(config),get_screenshot() 返回 False,调用方应回退到直接截图") - self._last_streaming_state_log_ts = now - return False + time.sleep(1.0) # 异常时等待1秒再继续 + + def get_screenshot(self, device_id: str, force: bool = False) -> bool: + """获取截图(优先使用缓存) + + 参数: + device_id: 设备ID + force: 是否强制重新截图(忽略缓存) + + 返回: + 是否成功获取截图 + """ + request_start = time.time() + timetag = datetime.now().strftime("%H:%M:%S") + + # 如果设备ID不同,需要重新启动服务 if self._current_device_id != device_id: + print(f"[{timetag}] [截图服务] 设备ID变更,重新启动服务: {device_id}") self.start(device_id) + # 等待第一次截图完成 time.sleep(0.1) - + + # 检查缓存是否有效 if not force: now = time.time() - if now - self._last_screenshot_time < self._cache_valid_duration and self._screenshot_path and os.path.exists(self._screenshot_path): - try: - size = os.path.getsize(self._screenshot_path) - if size >= 1024: - with open(self._screenshot_path, "rb") as f: - header = f.read(4) - if header == b"\x89PNG": - # If the cached file is a valid recent PNG, treat it as a successful cached screenshot. - # Do not rely on _last_success which may have been overwritten by later failed attempts. - return True - except Exception: - pass + time_since_last = now - self._last_screenshot_time - try: - return bool(self._screenshot_ops.get_screenshot(device_id, use_service=False)) # type: ignore[arg-type] - except Exception: - return False + # 修复:添加边界检查,避免负数或异常值 + if time_since_last < 0: + time_since_last = 0 # 避免时钟回拨导致的负数 + elif time_since_last > 86400: # 如果超过24小时,可能是时间戳错误 + time_since_last = 10.0 # 重置为10秒前 + # 检查缓存是否有效(时间 + 文件存在 + 文件完整性) + if time_since_last < self._cache_valid_duration: + if self._screenshot_path and os.path.exists(self._screenshot_path): + # 验证文件完整性(避免读取到不完整的文件) + # 使用重试机制,等待文件写入完成 + for retry in range(3): + try: + file_size = os.path.getsize(self._screenshot_path) + if file_size >= 1024: # PNG文件至少1KB + # 尝试快速验证文件头(PNG文件头:89 50 4E 47) + with open(self._screenshot_path, 'rb') as f: + header = f.read(4) + if header == b'\x89PNG': + # 验证文件尾(PNG文件尾:IEND) + # 更宽松的验证:检查文件末尾50字节内是否有IEND + try: + # 读取文件末尾50字节 + read_size = min(50, file_size) + f.seek(-read_size, 2) + footer = f.read(read_size) + if b'IEND' in footer: + elapsed = (time.time() - request_start) * 1000 + print(f"[{timetag}] [截图服务] [OK] 缓存命中,耗时: {elapsed:.1f}ms (距离上次截图: {time_since_last*1000:.0f}ms, 文件大小: {file_size/1024:.1f}KB)") + return True + elif retry < 2: + # 文件可能还在写入,等待一下 + time.sleep(0.1) + continue + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件不完整(文件尾验证失败),等待后台截图") + except (OSError, IOError) as e: + if retry < 2: + time.sleep(0.1) + continue + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件读取失败: {e},等待后台截图") + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件格式错误,等待后台截图") + break + else: + if retry < 2: + time.sleep(0.05) + continue + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件太小 ({file_size}B),等待后台截图") + except (OSError, IOError) as e: + if retry < 2: + time.sleep(0.05) + continue + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件检查失败: {e},等待后台截图") + except ValueError as e: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件检查异常: {e},等待后台截图") + break + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件不存在,等待后台截图") + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存已过期 (距离上次: {time_since_last*1000:.0f}ms > {self._cache_valid_duration*1000:.0f}ms),等待后台截图") + + # 缓存无效或强制刷新 + if force: + print(f"[{timetag}] [截图服务] 🔄 强制刷新,忽略缓存") + + # 等待后台截图完成 + if self._running: + wait_start = time.time() + time_since_last_before_wait = time.time() - self._last_screenshot_time + # 修复:添加边界检查 + if time_since_last_before_wait < 0: + time_since_last_before_wait = 0 + elif time_since_last_before_wait > 86400: + time_since_last_before_wait = 10.0 + print(f"[{timetag}] [截图服务] [WAIT] 缓存未命中,等待后台截图 (距离上次: {time_since_last_before_wait*1000:.0f}ms)") + + # 等待最多6秒,让后台线程完成截图(适应较慢的截图操作) + max_wait_time = 6.0 + while time.time() - wait_start < max_wait_time: + if self._last_screenshot_time > wait_start - 0.1: + # 截图已完成,验证文件完整性 + if self._screenshot_path and os.path.exists(self._screenshot_path): + try: + file_size = os.path.getsize(self._screenshot_path) + if file_size >= 1024: + with open(self._screenshot_path, 'rb') as f: + header = f.read(4) + if header == b'\x89PNG': + # 验证文件尾(更宽松的验证) + read_size = min(50, file_size) + f.seek(-read_size, 2) + footer = f.read(read_size) + if b'IEND' in footer: + wait_elapsed = (time.time() - wait_start) * 1000 + total_elapsed = (time.time() - request_start) * 1000 + status = "[OK]" if self._last_success else "[FAIL]" + print(f"[{timetag}] [截图服务] {status} 后台截图完成,等待耗时: {wait_elapsed:.1f}ms,总耗时: {total_elapsed:.1f}ms,文件大小: {file_size/1024:.1f}KB") + return self._last_success + # 文件尾验证失败,继续等待 + # 文件太小或格式错误,继续等待 + except (OSError, IOError, ValueError): + # 文件验证失败,继续等待 + pass + time.sleep(0.1) + + # 等待超时 + wait_elapsed = (time.time() - wait_start) * 1000 + print(f"[{timetag}] [截图服务] [TIMEOUT] 等待超时 ({wait_elapsed:.1f}ms),回退到直接截图") + + # 如果后台服务未运行或等待超时,直接执行截图(禁用服务模式,避免递归) + direct_start = time.time() + result = self._screenshot_ops.get_screenshot(device_id, use_service=False) # type: ignore[arg-type] + direct_elapsed = (time.time() - direct_start) * 1000 + total_elapsed = (time.time() - request_start) * 1000 + status = "[OK]" if result else "[FAIL]" + print(f"[{timetag}] [截图服务] {status} 直接截图完成,耗时: {direct_elapsed:.0f}ms,总耗时: {total_elapsed:.1f}ms") + return result + def is_running(self) -> bool: + """检查服务是否正在运行""" return self._running - - def get_cache_info(self) -> Dict[str, Any]: + + def get_last_screenshot_time(self) -> float: + """获取最后一次截图的时间戳""" + return self._last_screenshot_time + + def get_cache_info(self) -> dict: + """获取缓存信息(用于调试)""" return { "running": self._running, "device_id": self._current_device_id, @@ -224,15 +308,362 @@ class ScreenshotService: def get_optimal_workers() -> int: + """根据CPU核心数获取最优线程数 + + 返回: + 推荐的线程数 + """ cpu_count = os.cpu_count() or 4 + + # 针对12核CPU的优化配置 if cpu_count >= 12: - return 10 - if cpu_count >= 8: - return 8 - if cpu_count >= 4: - return 6 - if cpu_count >= 2: - return 3 - return 2 + return 10 # 12核:使用10个线程 + elif cpu_count >= 8: + return 8 # 8核:使用8个线程 + elif cpu_count >= 4: + return 6 # 4核:使用6个线程 + elif cpu_count >= 2: + return 3 # 2核:使用3个线程 + else: + return 2 # 单核:使用2个线程(I/O等待) - \ No newline at end of file + + + +"""后台截图服务:持续截图,主流程直接读取最新截图 + +功能: +1. 后台持续截图,避免主流程等待 +2. 截图缓存机制,减少重复截图 +3. 智能线程数配置,根据CPU核心数自动调整 +""" + +from __future__ import annotations + +import os +import threading +import time +from typing import Optional +from datetime import datetime +import path_config +from operations.screenshot_operations import ScreenshotOperations + + +class ScreenshotService: + """后台截图服务:持续截图,避免主流程等待""" + + _instance: Optional['ScreenshotService'] = None + _lock = threading.Lock() + + def __init__(self): + self._running: bool = False + self._thread: Optional[threading.Thread] = None + self._screenshot_ops: ScreenshotOperations = ScreenshotOperations() + self._current_device_id: Optional[str] = None + # 修复:初始化为过去时间,确保第一次请求时缓存过期但时间差合理 + self._last_screenshot_time = time.time() - 10.0 # 10秒前,避免巨大时间差 + self._screenshot_interval = 3.5 # 增加间隔到3.5秒,适应实际截图耗时 + self._cache_valid_duration = 4.0 # 增加缓存有效期到4.0秒,避免频繁过期 + self._screenshot_path: Optional[str] = None + self._last_success = False # 最后一次截图是否成功 + + @classmethod + def get_instance(cls) -> 'ScreenshotService': + """获取单例实例""" + if cls._instance is None: + with cls._lock: + if cls._instance is None: + cls._instance = cls() + return cls._instance + + def start(self, device_id: str, interval: float = 1.5): + """启动后台截图服务 + + 参数: + device_id: 设备ID + interval: 截图间隔(秒),默认1.5秒 + """ + with self._lock: + if self._running: + if self._current_device_id == device_id: + return # 已经在运行,且设备ID相同 + self.stop() # 设备ID不同,先停止 + + self._current_device_id = device_id + self._screenshot_interval = max(0.5, interval) # 最小0.5秒 + self._running = True + + # 初始化截图路径 + try: + self._screenshot_path = path_config.get_screenshot_path() + except (ImportError, AttributeError, OSError): + self._screenshot_path = os.path.join("pic", "screenshot.png") + + self._thread = threading.Thread( + target=self._screenshot_loop, + daemon=True, + name="ScreenshotService" + ) + self._thread.start() + # 修复:设置时间戳为过去足够长的时间,确保第一次请求能等到后台截图完成 + self._last_screenshot_time = time.time() - self._cache_valid_duration - 1.0 # 确保缓存过期但不至于太旧 + timetag = datetime.now().strftime("%H:%M:%S") + print(f"[{timetag}] [截图服务] 已启动后台截图服务,设备: {device_id}, 间隔: {interval}秒") + + def stop(self): + """停止后台截图服务""" + with self._lock: + if not self._running: + return + self._running = False + + if self._thread and self._thread.is_alive(): + self._thread.join(timeout=2.0) + timetag = datetime.now().strftime("%H:%M:%S") + print(f"[{timetag}] [截图服务] 已停止后台截图服务") + + def _screenshot_loop(self): + """后台截图循环""" + loop_count = 0 + while self._running: + try: + device_id = self._current_device_id + if not device_id: + time.sleep(0.1) + continue + + loop_count += 1 + timetag = datetime.now().strftime("%H:%M:%S") + screenshot_start = time.time() + + # 执行截图(禁用服务模式,避免递归) + success = self._screenshot_ops.get_screenshot(device_id, use_service=False) # type: ignore[arg-type] + + screenshot_elapsed = (time.time() - screenshot_start) * 1000 + if success: + # 验证文件完整性后再更新时间戳(避免读取到不完整的文件) + if self._screenshot_path and os.path.exists(self._screenshot_path): + try: + file_size = os.path.getsize(self._screenshot_path) + if file_size >= 1024: + with open(self._screenshot_path, 'rb') as f: + header = f.read(4) + if header == b'\x89PNG': + self._last_screenshot_time = time.time() + self._last_success = True + print(f"[{timetag}] [截图服务] 后台截图完成 #{loop_count},耗时: {screenshot_elapsed:.0f}ms,文件大小: {file_size/1024:.1f}KB") + else: + self._last_success = False + print(f"[{timetag}] [截图服务] 后台截图文件格式错误 #{loop_count},耗时: {screenshot_elapsed:.0f}ms") + else: + self._last_success = False + print(f"[{timetag}] [截图服务] 后台截图文件太小 #{loop_count} ({file_size}B),耗时: {screenshot_elapsed:.0f}ms") + except (OSError, IOError, ValueError) as e: + self._last_success = False + print(f"[{timetag}] [截图服务] 后台截图文件验证失败 #{loop_count}: {e},耗时: {screenshot_elapsed:.0f}ms") + else: + self._last_success = False + print(f"[{timetag}] [截图服务] 后台截图文件不存在 #{loop_count},耗时: {screenshot_elapsed:.0f}ms") + else: + self._last_success = False + print(f"[{timetag}] [截图服务] 后台截图失败 #{loop_count},耗时: {screenshot_elapsed:.0f}ms") + + # 等待间隔时间,确保不小于0.5秒 + remaining_interval = max(0.5, self._screenshot_interval - screenshot_elapsed / 1000) + time.sleep(remaining_interval) + except Exception as e: + try: + timetag = datetime.now().strftime("%H:%M:%S") + print(f"[{timetag}] [截图服务] 后台截图异常: {e}") + import traceback + traceback.print_exc() + except Exception: + pass + time.sleep(1.0) # 异常时等待1秒再继续 + + def get_screenshot(self, device_id: str, force: bool = False) -> bool: + """获取截图(优先使用缓存) + + 参数: + device_id: 设备ID + force: 是否强制重新截图(忽略缓存) + + 返回: + 是否成功获取截图 + """ + request_start = time.time() + timetag = datetime.now().strftime("%H:%M:%S") + + # 如果设备ID不同,需要重新启动服务 + if self._current_device_id != device_id: + print(f"[{timetag}] [截图服务] 设备ID变更,重新启动服务: {device_id}") + self.start(device_id) + # 等待第一次截图完成 + time.sleep(0.1) + + # 检查缓存是否有效 + if not force: + now = time.time() + time_since_last = now - self._last_screenshot_time + + # 修复:添加边界检查,避免负数或异常值 + if time_since_last < 0: + time_since_last = 0 # 避免时钟回拨导致的负数 + elif time_since_last > 86400: # 如果超过24小时,可能是时间戳错误 + time_since_last = 10.0 # 重置为10秒前 + + # 检查缓存是否有效(时间 + 文件存在 + 文件完整性) + if time_since_last < self._cache_valid_duration: + if self._screenshot_path and os.path.exists(self._screenshot_path): + # 验证文件完整性(避免读取到不完整的文件) + # 使用重试机制,等待文件写入完成 + for retry in range(3): + try: + file_size = os.path.getsize(self._screenshot_path) + if file_size >= 1024: # PNG文件至少1KB + # 尝试快速验证文件头(PNG文件头:89 50 4E 47) + with open(self._screenshot_path, 'rb') as f: + header = f.read(4) + if header == b'\x89PNG': + # 验证文件尾(PNG文件尾:IEND) + # 更宽松的验证:检查文件末尾50字节内是否有IEND + try: + # 读取文件末尾50字节 + read_size = min(50, file_size) + f.seek(-read_size, 2) + footer = f.read(read_size) + if b'IEND' in footer: + elapsed = (time.time() - request_start) * 1000 + print(f"[{timetag}] [截图服务] [OK] 缓存命中,耗时: {elapsed:.1f}ms (距离上次截图: {time_since_last*1000:.0f}ms, 文件大小: {file_size/1024:.1f}KB)") + return True + elif retry < 2: + # 文件可能还在写入,等待一下 + time.sleep(0.1) + continue + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件不完整(文件尾验证失败),等待后台截图") + except (OSError, IOError) as e: + if retry < 2: + time.sleep(0.1) + continue + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件读取失败: {e},等待后台截图") + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件格式错误,等待后台截图") + break + else: + if retry < 2: + time.sleep(0.05) + continue + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件太小 ({file_size}B),等待后台截图") + except (OSError, IOError) as e: + if retry < 2: + time.sleep(0.05) + continue + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件检查失败: {e},等待后台截图") + except ValueError as e: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件检查异常: {e},等待后台截图") + break + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存文件不存在,等待后台截图") + else: + print(f"[{timetag}] [截图服务] [WARN] 缓存已过期 (距离上次: {time_since_last*1000:.0f}ms > {self._cache_valid_duration*1000:.0f}ms),等待后台截图") + + # 缓存无效或强制刷新 + if force: + print(f"[{timetag}] [截图服务] 强制刷新,忽略缓存") + + # 等待后台截图完成 + if self._running: + wait_start = time.time() + time_since_last_before_wait = time.time() - self._last_screenshot_time + # 修复:添加边界检查 + if time_since_last_before_wait < 0: + time_since_last_before_wait = 0 + elif time_since_last_before_wait > 86400: + time_since_last_before_wait = 10.0 + print(f"[{timetag}] [截图服务] [WAIT] 缓存未命中,等待后台截图 (距离上次: {time_since_last_before_wait*1000:.0f}ms)") + + # 等待最多6秒,让后台线程完成截图(适应较慢的截图操作) + max_wait_time = 6.0 + while time.time() - wait_start < max_wait_time: + if self._last_screenshot_time > wait_start - 0.1: + # 截图已完成,验证文件完整性 + if self._screenshot_path and os.path.exists(self._screenshot_path): + try: + file_size = os.path.getsize(self._screenshot_path) + if file_size >= 1024: + with open(self._screenshot_path, 'rb') as f: + header = f.read(4) + if header == b'\x89PNG': + # 验证文件尾(更宽松的验证) + read_size = min(50, file_size) + f.seek(-read_size, 2) + footer = f.read(read_size) + if b'IEND' in footer: + wait_elapsed = (time.time() - wait_start) * 1000 + total_elapsed = (time.time() - request_start) * 1000 + status = "[OK]" if self._last_success else "[FAIL]" + print(f"[{timetag}] [截图服务] {status} 后台截图完成,等待耗时: {wait_elapsed:.1f}ms,总耗时: {total_elapsed:.1f}ms,文件大小: {file_size/1024:.1f}KB") + return self._last_success + # 文件尾验证失败,继续等待 + # 文件太小或格式错误,继续等待 + except (OSError, IOError, ValueError): + # 文件验证失败,继续等待 + pass + time.sleep(0.1) + + # 等待超时 + wait_elapsed = (time.time() - wait_start) * 1000 + print(f"[{timetag}] [截图服务] [TIMEOUT] 等待超时 ({wait_elapsed:.1f}ms),回退到直接截图") + + # 如果后台服务未运行或等待超时,直接执行截图(禁用服务模式,避免递归) + direct_start = time.time() + result = self._screenshot_ops.get_screenshot(device_id, use_service=False) # type: ignore[arg-type] + direct_elapsed = (time.time() - direct_start) * 1000 + total_elapsed = (time.time() - request_start) * 1000 + status = "[OK]" if result else "[FAIL]" + print(f"[{timetag}] [截图服务] {status} 直接截图完成,耗时: {direct_elapsed:.0f}ms,总耗时: {total_elapsed:.1f}ms") + return result + + def is_running(self) -> bool: + """检查服务是否正在运行""" + return self._running + + def get_last_screenshot_time(self) -> float: + """获取最后一次截图的时间戳""" + return self._last_screenshot_time + + def get_cache_info(self) -> dict: + """获取缓存信息(用于调试)""" + return { + "running": self._running, + "device_id": self._current_device_id, + "last_screenshot_time": self._last_screenshot_time, + "interval": self._screenshot_interval, + "cache_valid_duration": self._cache_valid_duration, + "last_success": self._last_success, + } + + +def get_optimal_workers() -> int: + """根据CPU核心数获取最优线程数 + + 返回: + 推荐的线程数 + """ + cpu_count = os.cpu_count() or 4 + + # 针对12核CPU的优化配置 + if cpu_count >= 12: + return 10 # 12核:使用10个线程 + elif cpu_count >= 8: + return 8 # 8核:使用8个线程 + elif cpu_count >= 4: + return 6 # 4核:使用6个线程 + elif cpu_count >= 2: + return 3 # 2核:使用3个线程 + else: + return 2 # 单核:使用2个线程(I/O等待) diff --git a/operations/screenshot_service_new.py b/operations/screenshot_service_new.py new file mode 100644 index 0000000..e1f23f3 --- /dev/null +++ b/operations/screenshot_service_new.py @@ -0,0 +1,136 @@ +"""简化版后台截图服务,避免文件中重复定义导致的 linter 错误。""" + +from __future__ import annotations + +import os +import threading +import time +from typing import Optional +from datetime import datetime +import path_config +from operations.screenshot_operations import ScreenshotOperations + + +class ScreenshotService: + """后台截图服务(简化实现)。""" + + _instance: Optional["ScreenshotService"] = None + _lock = threading.Lock() + + def __init__(self): + self._running = False + self._thread: Optional[threading.Thread] = None + self._screenshot_ops = ScreenshotOperations() + self._current_device_id: Optional[str] = None + self._last_screenshot_time = time.time() - 10.0 + self._screenshot_interval = 3.5 + self._cache_valid_duration = 4.0 + self._screenshot_path: Optional[str] = None + self._last_success = False + + @classmethod + def get_instance(cls) -> "ScreenshotService": + if cls._instance is None: + with cls._lock: + if cls._instance is None: + cls._instance = cls() + assert cls._instance is not None + return cls._instance + + def start(self, device_id: str, interval: float = 1.5): + with self._lock: + if self._running and self._current_device_id == device_id: + return + if self._running: + self.stop() + self._current_device_id = device_id + self._screenshot_interval = max(0.5, interval) + self._running = True + try: + self._screenshot_path = path_config.get_screenshot_path() + except Exception: + self._screenshot_path = os.path.join("pic", "screenshot.png") + self._thread = threading.Thread(target=self._screenshot_loop, daemon=True, name="ScreenshotService") + self._thread.start() + self._last_screenshot_time = time.time() - self._cache_valid_duration - 1.0 + timetag = datetime.now().strftime("%H:%M:%S") + print(f"[{timetag}] [截图服务] 已启动后台截图服务,设备: {device_id}, 间隔: {interval}秒") + + def stop(self): + with self._lock: + if not self._running: + return + self._running = False + if self._thread and self._thread.is_alive(): + self._thread.join(timeout=2.0) + timetag = datetime.now().strftime("%H:%M:%S") + print(f"[{timetag}] [截图服务] 已停止后台截图服务") + + def _screenshot_loop(self): + while self._running: + try: + if not self._current_device_id: + time.sleep(0.1) + continue + start = time.time() + success = self._screenshot_ops.get_screenshot(self._current_device_id, use_service=False) + elapsed = (time.time() - start) * 1000 + timetag = datetime.now().strftime("%H:%M:%S") + if success: + self._last_screenshot_time = time.time() + self._last_success = True + print(f"[{timetag}] [截图服务] 后台截图成功,耗时: {elapsed:.0f}ms") + else: + self._last_success = False + print(f"[{timetag}] [截图服务] 后台截图失败,耗时: {elapsed:.0f}ms") + time.sleep(max(0.5, self._screenshot_interval - elapsed / 1000)) + except Exception as e: + print(f"[截图服务] 异常: {e}") + time.sleep(1.0) + + def get_screenshot(self, device_id: str, force: bool = False) -> bool: + # 优先使用缓存判断,简化版保留核心逻辑 + if self._current_device_id != device_id: + self.start(device_id) + time.sleep(0.1) + now = time.time() + if not force and now - self._last_screenshot_time < self._cache_valid_duration: + if self._screenshot_path and os.path.exists(self._screenshot_path): + try: + if os.path.getsize(self._screenshot_path) >= 1024: + return True + except Exception: + pass + # 回退到直接截图 + return self._screenshot_ops.get_screenshot(device_id, use_service=False) + + def is_running(self) -> bool: + return self._running + + def get_last_screenshot_time(self) -> float: + return self._last_screenshot_time + + def get_cache_info(self) -> dict: + return { + "running": self._running, + "device_id": self._current_device_id, + "last_screenshot_time": self._last_screenshot_time, + "interval": self._screenshot_interval, + "cache_valid_duration": self._cache_valid_duration, + "last_success": self._last_success, + } + + +def get_optimal_workers() -> int: + cpu_count = os.cpu_count() or 4 + if cpu_count >= 12: + return 10 + if cpu_count >= 8: + return 8 + if cpu_count >= 4: + return 6 + if cpu_count >= 2: + return 3 + return 2 + + diff --git a/restore_screenshot_service.py b/restore_screenshot_service.py index 389d00c..b1bab9b 100644 --- a/restore_screenshot_service.py +++ b/restore_screenshot_service.py @@ -351,3 +351,4 @@ print('ScreenshotService file restored successfully') + diff --git a/test_adb_screenshot_timing.py b/test_adb_screenshot_timing.py index a218592..b81ea39 100644 --- a/test_adb_screenshot_timing.py +++ b/test_adb_screenshot_timing.py @@ -222,3 +222,4 @@ if __name__ == "__main__": main() + diff --git a/test_loop_screenshot_stop.py b/test_loop_screenshot_stop.py index d82bcef..bb7c3ff 100644 --- a/test_loop_screenshot_stop.py +++ b/test_loop_screenshot_stop.py @@ -96,3 +96,4 @@ if __name__ == "__main__": + diff --git a/test_ocr_multithread.py b/test_ocr_multithread.py index 65b1e1a..7d4b779 100644 --- a/test_ocr_multithread.py +++ b/test_ocr_multithread.py @@ -105,3 +105,4 @@ if __name__ == "__main__": + diff --git a/test_parallel_ocr_quick.py b/test_parallel_ocr_quick.py index 809db2e..346287c 100644 --- a/test_parallel_ocr_quick.py +++ b/test_parallel_ocr_quick.py @@ -146,3 +146,4 @@ if __name__ == "__main__": + diff --git a/test_parallel_ocr_simple.py b/test_parallel_ocr_simple.py index be1ae32..da983e6 100644 --- a/test_parallel_ocr_simple.py +++ b/test_parallel_ocr_simple.py @@ -210,3 +210,4 @@ if __name__ == "__main__": + diff --git a/test_screenshot_error_handling.py b/test_screenshot_error_handling.py index 05774c5..42cb80b 100644 --- a/test_screenshot_error_handling.py +++ b/test_screenshot_error_handling.py @@ -110,3 +110,4 @@ if __name__ == "__main__": + diff --git a/tools/README_Region_Selector.md b/tools/README_Region_Selector.md index 86fe3d7..9232c1d 100644 --- a/tools/README_Region_Selector.md +++ b/tools/README_Region_Selector.md @@ -139,3 +139,4 @@ python region_selector.py path/to/image.png +