diff --git a/modules/terminal_ops.py b/modules/terminal_ops.py index c0ac1da..0f903e4 100644 --- a/modules/terminal_ops.py +++ b/modules/terminal_ops.py @@ -537,6 +537,13 @@ class TerminalOperator: process.kill() except Exception: pass + # 取消读取任务,避免孤儿任务 + stdout_task.cancel() + stderr_task.cancel() + try: + await asyncio.gather(stdout_task, stderr_task, return_exceptions=True) + except Exception: + pass raise # 确保读取协程结束 diff --git a/server/chat_flow_tool_loop.py b/server/chat_flow_tool_loop.py index 61989c7..5502555 100644 --- a/server/chat_flow_tool_loop.py +++ b/server/chat_flow_tool_loop.py @@ -484,3 +484,5 @@ async def execute_tool_calls(*, web_terminal, tool_calls, sender, messages, clie return {"stopped": False, "last_tool_call_time": last_tool_call_time} + +