mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-29 18:46:59 +00:00
fix(tools): keep command TTS deadline through exit
This commit is contained in:
parent
1b97e3efc5
commit
4e8a66dace
3 changed files with 36 additions and 9 deletions
|
|
@ -1026,17 +1026,13 @@ def _run_command_tts(command: str, timeout: float) -> subprocess.CompletedProces
|
|||
|
||||
def read_stream(name: str, stream: Any) -> None:
|
||||
encoding = getattr(stream, "encoding", None) or "utf-8"
|
||||
read1 = getattr(getattr(stream, "buffer", None), "read1", None)
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
fd = stream.fileno()
|
||||
except (AttributeError, OSError):
|
||||
fd = None
|
||||
|
||||
if fd is None:
|
||||
if read1 is None:
|
||||
chunk = stream.read(65536)
|
||||
else:
|
||||
data = os.read(fd, 65536)
|
||||
data = read1(65536)
|
||||
chunk = data.decode(encoding, errors="replace")
|
||||
if not chunk:
|
||||
break
|
||||
|
|
@ -1076,6 +1072,12 @@ def _run_command_tts(command: str, timeout: float) -> subprocess.CompletedProces
|
|||
chunks[name].append(chunk)
|
||||
deadline = time.monotonic() + timeout
|
||||
|
||||
if not timed_out:
|
||||
try:
|
||||
proc.wait(timeout=max(0.0, deadline - time.monotonic()))
|
||||
except subprocess.TimeoutExpired:
|
||||
timed_out = True
|
||||
|
||||
if timed_out:
|
||||
_terminate_command_tts_process_tree(proc)
|
||||
for reader in readers:
|
||||
|
|
@ -1101,7 +1103,6 @@ def _run_command_tts(command: str, timeout: float) -> subprocess.CompletedProces
|
|||
|
||||
stdout = "".join(chunks["stdout"])
|
||||
stderr = "".join(chunks["stderr"])
|
||||
proc.wait()
|
||||
|
||||
if proc.returncode:
|
||||
raise subprocess.CalledProcessError(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue