mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-04-02 17:32:39 +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 typing import Any
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from nanobot.agent.tools.base import Tool
|
||||
|
||||
|
||||
@ -109,12 +111,12 @@ class ExecTool(Tool):
|
||||
try:
|
||||
await asyncio.wait_for(process.wait(), timeout=5.0)
|
||||
except asyncio.TimeoutError:
|
||||
pass
|
||||
finally:
|
||||
try:
|
||||
os.waitpid(process.pid, os.WNOHANG)
|
||||
except (ProcessLookupError, ChildProcessError):
|
||||
pass
|
||||
except ProcessLookupError:
|
||||
pass
|
||||
return f"Error: Command timed out after {effective_timeout} seconds"
|
||||
|
||||
output_parts = []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user