From b4f69f2cffad194aa07becbd53688885f97475ec Mon Sep 17 00:00:00 2001 From: lixiangcheng1 Date: Tue, 24 Feb 2026 18:29:31 +0800 Subject: [PATCH] [fix]Force re-importing Trio in child processes (to avoid inheriting the state of the parent process) --- api/app/tasks.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api/app/tasks.py b/api/app/tasks.py index e29d0406..99755b83 100644 --- a/api/app/tasks.py +++ b/api/app/tasks.py @@ -13,7 +13,6 @@ from typing import Any, Dict, List, Optional import redis import requests -import trio # Import a unified Celery instance from app.celery_app import celery_app @@ -65,6 +64,10 @@ def parse_document(file_path: str, document_id: uuid.UUID): """ Document parsing, vectorization, and storage """ + # Force re-importing Trio in child processes (to avoid inheriting the state of the parent process) + import trio + import importlib + importlib.reload(trio) db = next(get_db()) # Manually call the generator db_document = None db_knowledge = None @@ -291,6 +294,10 @@ def build_graphrag_for_kb(kb_id: uuid.UUID): """ build knowledge graph """ + # Force re-importing Trio in child processes (to avoid inheriting the state of the parent process) + import trio + import importlib + importlib.reload(trio) db = next(get_db()) # Manually call the generator db_documents = None db_knowledge = None