(self, settings: Settings | None = None)
| 105 | executor = self._ensure_executor() |
| 106 | timeout = max(self.settings.tencent_ocr_timeout_seconds, 1) |
| 107 | # 首次启动先保证模型在主进程完整落地,再做单 worker 预热, |
| 108 | # 避免 Windows 下多个进程同时下载/加载同一个 onnx 文件导致文件占用和损坏竞争。 |
| 109 | future = executor.submit(_warmup_worker, 0) |
| 110 | future.result(timeout=timeout) |
| 111 | |
| 112 | def shutdown(self) -> None: |
| 113 | with self._executor_lock: |
| 114 | if self._executor is None: |
| 115 | return |
| 116 | self._executor.shutdown(wait=False, cancel_futures=True) |
| 117 | self._executor = None |
| 118 | |
| 119 | def analyze_captcha_image(self, image_bytes: bytes, *, prompt_text: str) -> dict[str, Any]: |
| 120 | if not self.settings.tencent_ocr_enabled: |
| 121 | raise BadRequestError("本地 OCR 已关闭,请设置 TENCENT_OCR_ENABLED=1") |
| 122 | |
| 123 | missing = self._missing_dependencies() |
| 124 | if missing: |
| 125 | raise BadRequestError( |
| 126 | "本地 OCR 依赖没装全,先运行 pip install -r requirements.txt,别让发动机缺缸还硬跑。", |
nothing calls this directly
no test coverage detected