fix: add timeout to subprocess.run() and proc.wait() calls
subprocess.run() and proc.wait() without timeout can hang indefinitely if the child process becomes unresponsive. This blocks the calling thread forever. Fixed locations: - tools/transcription_tools.py: ffmpeg conversion (timeout=300) and user-configured STT commands with shell=True (timeout=300) - gateway/run.py: helper script proc.wait() (timeout=3600) Not fixed: - agent/anthropic_adapter.py: interactive 'claude setup-token' — user-driven, timeout would be inappropriate
This commit is contained in:
+1
-1
@@ -15126,7 +15126,7 @@ class GatewayRunner:
|
|||||||
env["PYTHONUNBUFFERED"] = "1"
|
env["PYTHONUNBUFFERED"] = "1"
|
||||||
with open(output_path, "wb") as f:
|
with open(output_path, "wb") as f:
|
||||||
proc = subprocess.Popen(cmd, stdout=f, stderr=subprocess.STDOUT, env=env)
|
proc = subprocess.Popen(cmd, stdout=f, stderr=subprocess.STDOUT, env=env)
|
||||||
rc = proc.wait()
|
rc = proc.wait(timeout=3600)
|
||||||
with open(exit_code_path, "w") as f:
|
with open(exit_code_path, "w") as f:
|
||||||
f.write(str(rc))
|
f.write(str(rc))
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1186,7 +1186,7 @@ def _prepare_local_audio(file_path: str, work_dir: str) -> tuple[Optional[str],
|
|||||||
command = [ffmpeg, "-y", "-i", file_path, converted_path]
|
command = [ffmpeg, "-y", "-i", file_path, converted_path]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(command, check=True, capture_output=True, text=True)
|
subprocess.run(command, check=True, capture_output=True, text=True, timeout=300)
|
||||||
return converted_path, None
|
return converted_path, None
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
details = e.stderr.strip() or e.stdout.strip() or str(e)
|
details = e.stderr.strip() or e.stdout.strip() or str(e)
|
||||||
@@ -1229,9 +1229,9 @@ def _transcribe_local_command(file_path: str, model_name: str) -> Dict[str, Any]
|
|||||||
# User-provided templates (env var) may contain shell syntax; auto-detected commands are safe for list mode.
|
# User-provided templates (env var) may contain shell syntax; auto-detected commands are safe for list mode.
|
||||||
use_shell = bool(os.getenv(LOCAL_STT_COMMAND_ENV, "").strip())
|
use_shell = bool(os.getenv(LOCAL_STT_COMMAND_ENV, "").strip())
|
||||||
if use_shell:
|
if use_shell:
|
||||||
subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
|
subprocess.run(command, shell=True, check=True, capture_output=True, text=True, timeout=300)
|
||||||
else:
|
else:
|
||||||
subprocess.run(shlex.split(command), check=True, capture_output=True, text=True)
|
subprocess.run(shlex.split(command), check=True, capture_output=True, text=True, timeout=300)
|
||||||
|
|
||||||
|
|
||||||
txt_files = sorted(Path(output_dir).glob("*.txt"))
|
txt_files = sorted(Path(output_dir).glob("*.txt"))
|
||||||
|
|||||||
Reference in New Issue
Block a user