mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-01 15:25:56 +00:00
refactor(shell): use finally block to reap zombie processes on timeout
This commit is contained in:
parent
e423ceef9c
commit
dbcc7cb539
@ -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 = []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user