diff --git a/tests/integration/fixtures/common.py b/tests/integration/fixtures/common.py index 27b2d6dc3..28a047ea5 100644 --- a/tests/integration/fixtures/common.py +++ b/tests/integration/fixtures/common.py @@ -6,6 +6,7 @@ import inspect import os +import signal import socket import subprocess import tempfile @@ -45,6 +46,8 @@ def start_llama_stack_server(config_name: str) -> subprocess.Popen: stderr=subprocess.PIPE, # keep stderr to see errors text=True, env={**os.environ, "LLAMA_STACK_LOG_FILE": "server.log"}, + # Create new process group so we can kill all child processes + preexec_fn=os.setsid, ) return process @@ -267,14 +270,17 @@ def cleanup_server_process(request): print(f"Server process already terminated with return code: {server_process.returncode}") return try: - server_process.terminate() + print(f"Terminating process {server_process.pid} and its group...") + # Kill the entire process group + os.killpg(os.getpgid(server_process.pid), signal.SIGTERM) server_process.wait(timeout=10) - print("Server process terminated gracefully") + print("Server process and children terminated gracefully") except subprocess.TimeoutExpired: print("Server process did not terminate gracefully, killing it") - server_process.kill() + # Force kill the entire process group + os.killpg(os.getpgid(server_process.pid), signal.SIGKILL) server_process.wait() - print("Server process killed") + print("Server process and children killed") except Exception as e: print(f"Error during server cleanup: {e}") else: