EasyOCR修复: 1)worker加顶层异常捕获确保stderr可见 2)竞态保护:stdin写入前检查proc非None 3)增加处理日志 4)超时改30s
This commit is contained in:
+8
-2
@@ -1159,6 +1159,9 @@ class MessageMonitor:
|
||||
img_b64 = base64.b64encode(buf.getvalue()).decode()
|
||||
|
||||
with self._easyocr_lock:
|
||||
# ⚠ 竞态保护:另一个线程可能已杀死进程并设 None
|
||||
if not self._easyocr_proc or self._easyocr_proc.poll() is not None:
|
||||
return None
|
||||
self._easyocr_proc.stdin.write(json.dumps({"img": img_b64}) + "\n")
|
||||
self._easyocr_proc.stdin.flush()
|
||||
|
||||
@@ -1168,7 +1171,9 @@ class MessageMonitor:
|
||||
_q = Queue()
|
||||
def _read_worker():
|
||||
try:
|
||||
_q.put(self._easyocr_proc.stdout.readline())
|
||||
proc = self._easyocr_proc
|
||||
if proc and proc.poll() is None:
|
||||
_q.put(proc.stdout.readline())
|
||||
except Exception:
|
||||
pass
|
||||
_t = threading.Thread(target=_read_worker, daemon=True)
|
||||
@@ -1334,7 +1339,8 @@ class MessageMonitor:
|
||||
return
|
||||
# EasyOCR 用原图(1x):2x 图送 GPU 显存压力大 + 加速泄漏
|
||||
img_np = _np.array(im_original)
|
||||
text = self._call_easyocr_safe(img_np, timeout=10)
|
||||
# ⚠ 超时不能太短:首次加载模型 3-10s + 图片处理,10s 必超时
|
||||
text = self._call_easyocr_safe(img_np, timeout=30)
|
||||
if text:
|
||||
easy_text[0] = text
|
||||
|
||||
|
||||
Reference in New Issue
Block a user