refactor(shell): use finally block to reap zombie processes on timeout

This commit is contained in:
Eric Yang
2026-03-22 19:21:28 +00:00
committed by Xubin Ren
parent e423ceef9c
commit dbcc7cb539

View File

@@ -6,6 +6,8 @@ import re
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
from loguru import logger
from nanobot.agent.tools.base import Tool from nanobot.agent.tools.base import Tool
@@ -109,12 +111,12 @@ class ExecTool(Tool):
try: try:
await asyncio.wait_for(process.wait(), timeout=5.0) await asyncio.wait_for(process.wait(), timeout=5.0)
except asyncio.TimeoutError: except asyncio.TimeoutError:
pass
finally:
try: try:
os.waitpid(process.pid, os.WNOHANG) os.waitpid(process.pid, os.WNOHANG)
except (ProcessLookupError, ChildProcessError): except (ProcessLookupError, ChildProcessError):
pass pass
except ProcessLookupError:
pass
return f"Error: Command timed out after {effective_timeout} seconds" return f"Error: Command timed out after {effective_timeout} seconds"
output_parts = [] output_parts = []