diff --git a/agbenchmark/agent_interface.py b/agbenchmark/agent_interface.py index 6b2d5bbe..d93fe12e 100644 --- a/agbenchmark/agent_interface.py +++ b/agbenchmark/agent_interface.py @@ -6,6 +6,7 @@ import sys import time from typing import Any, Dict +import psutil from dotenv import load_dotenv from agbenchmark.start_benchmark import CURRENT_DIRECTORY, HOME_DIRECTORY @@ -67,7 +68,11 @@ def run_agent( if time.time() - start_time > timeout: print("The Python function has exceeded the time limit and was terminated.") - process.kill() + parent = psutil.Process(process.pid) + for child in parent.children(recursive=True): + child.kill() + parent.kill() + else: print("The Python function has finished running.")