修复commit charge阈值判断和OCR乱码字符检测
This commit is contained in:
+13
-6
@@ -1533,12 +1533,13 @@ class MessageMonitor:
|
||||
self._easyocr_retry_until = time.time() + 3600
|
||||
return False
|
||||
|
||||
# ⭐ 系统总提交量检查:提交量 > 1.5× 物理RAM 时冻结风险极高
|
||||
# ⭐ 系统总提交量检查:提交量 > 90% 总commit容量(物理+页面文件) 时冻结风险极高
|
||||
# torch/CUDA 加载需额外 ~6GB,提交量已超标时再加载必然触发换页风暴
|
||||
_commit_gb = _phys_used_gb + _page_used_gb
|
||||
_phys_total_gb_check = _phys_total_gb
|
||||
if _commit_gb > _phys_total_gb_check * 1.5:
|
||||
logger.error(f"[ocr] ⚠️ 系统提交量过高: {_commit_gb:.1f}GB > 1.5×物理RAM({_phys_total_gb_check:.1f}GB),"
|
||||
_commit_total_gb = _phys_total_gb + _page_total_gb
|
||||
_commit_pct = (_commit_gb / _commit_total_gb * 100) if _commit_total_gb > 0 else 0
|
||||
if _commit_pct > 90.0:
|
||||
logger.error(f"[ocr] ⚠️ 系统提交量过高: {_commit_gb:.1f}GB ({_commit_pct:.0f}%总commit容量{_commit_total_gb:.1f}GB),"
|
||||
f"EasyOCR 冷却1小时。当前物理{_phys_used_pct}%+页面{_page_used_pct}%。"
|
||||
f"建议:关闭占用内存的程序或增大物理内存")
|
||||
self._easyocr_retry_until = time.time() + 3600
|
||||
@@ -1593,10 +1594,12 @@ class MessageMonitor:
|
||||
|
||||
# ⭐ 页面文件百分比 + 总提交量双重检查:超阈值直接强制CPU(防冻结)
|
||||
_commit_check_gb = used_gb + swap_used_gb
|
||||
if swap_pct > 85.0 or _commit_check_gb > total_gb * 1.5:
|
||||
_commit_total_check_gb = total_gb + swap_total_gb
|
||||
_commit_check_pct = (_commit_check_gb / _commit_total_check_gb * 100) if _commit_total_check_gb > 0 else 0
|
||||
if swap_pct > 85.0 or _commit_check_pct > 90.0:
|
||||
_worker_env["EASYOCR_FORCE_CPU"] = "1"
|
||||
logger.warning(f"[ocr] 内存压力高(物理{mem.percent}%+页面{swap_pct}%,"
|
||||
f"总提交{_commit_check_gb:.1f}GB>{total_gb*1.5:.1f}GB阈值),"
|
||||
f"总提交{_commit_check_gb:.1f}GB ({_commit_check_pct:.0f}%总commit容量{_commit_total_check_gb:.1f}GB),"
|
||||
f"EasyOCR 子进程强制CPU模式(避免CUDA加载冻结)")
|
||||
elif available_gb < 3.0:
|
||||
_worker_env["EASYOCR_FORCE_CPU"] = "1"
|
||||
@@ -4401,6 +4404,10 @@ class MessageMonitor:
|
||||
if re.search(r'编辑权限', text):
|
||||
logger.debug(f"[ocr] 过滤器2结果: 检测到UI文本残留,返回True")
|
||||
return True
|
||||
# OCR乱码字符:§(Windows OCR常误读"互"为"§")、¶、©、®、™等非常规符号
|
||||
if re.search(r'[§¶©®™]', text):
|
||||
logger.debug(f"[ocr] 过滤器2结果: 检测到OCR乱码字符,返回True")
|
||||
return True
|
||||
logger.debug(f"[ocr] 过滤器2结果: 未检测到噪声特征,返回False")
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user