[fix]Force re-importing Trio in child processes (to avoid inheriting the state of the parent process)

This commit is contained in:
lixiangcheng1
2026-02-24 18:29:31 +08:00
parent b462e17a5b
commit b4f69f2cff

View File

@@ -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