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