Skip to content

Commit 0dc9291

Browse files
Update processor.py
1 parent b56e3e9 commit 0dc9291

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docker/app/processor.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,27 @@ def _run_mineru_cli(self, input_file: Path, output_dir: Path) -> Dict[str, Any]:
281281
f_dump_content_list=False,
282282
)
283283

284+
# 清理 vLLM 引擎单例,避免 EngineCore 子进程在后续任务中崩溃
285+
# vLLM v0.11.x 的 EngineCore 使用 multiprocessing spawn,
286+
# 长驻容器中引擎空闲后子进程可能进入不稳定状态
287+
try:
288+
from mineru.backend.vlm.vlm_analyze import ModelSingleton
289+
singleton = ModelSingleton()
290+
with singleton._lock:
291+
for key, predictor in list(singleton._models.items()):
292+
try:
293+
if hasattr(predictor, 'llm') and predictor.llm is not None:
294+
del predictor.llm
295+
if hasattr(predictor, 'close'):
296+
predictor.close()
297+
except Exception:
298+
pass
299+
singleton._models.clear()
300+
torch.cuda.empty_cache()
301+
logger.info("vLLM引擎单例已清理,下次任务将重新初始化")
302+
except Exception as e:
303+
logger.warning("vLLM引擎清理失败(非致命)", error=str(e))
304+
284305
processing_time = time.time() - start_time
285306

286307
# 验证输出文件

0 commit comments

Comments
 (0)