[fix]Force re-importing Trio in child processes (to avoid inheriting the state of the parent process)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@@ -368,7 +369,7 @@ def build_graphrag_for_kb(kb_id: uuid.UUID):
|
|||||||
print(f"{datetime.now().strftime('%H:%M:%S')} GraphRAG task result for task {task}:\n{result}\n")
|
print(f"{datetime.now().strftime('%H:%M:%S')} GraphRAG task result for task {task}:\n{result}\n")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
try:
|
def sync_task():
|
||||||
trio.run(
|
trio.run(
|
||||||
lambda: _run(
|
lambda: _run(
|
||||||
row=task,
|
row=task,
|
||||||
@@ -383,6 +384,10 @@ def build_graphrag_for_kb(kb_id: uuid.UUID):
|
|||||||
with_community=with_community,
|
with_community=with_community,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
with ThreadPoolExecutor(max_workers=1) as executor:
|
||||||
|
future = executor.submit(sync_task)
|
||||||
|
future.result() # Blocks until the task completes
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"{datetime.now().strftime('%H:%M:%S')} GraphRAG task failed for task {task}:\n{str(e)}\n")
|
print(f"{datetime.now().strftime('%H:%M:%S')} GraphRAG task failed for task {task}:\n{str(e)}\n")
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
Reference in New Issue
Block a user