Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

Kill all subprocesses (#265)

Erik Petersonfa8f010e800a
diff --git a/agbenchmark/agent_interface.py b/agbenchmark/agent_interface.py
index 6b2d5bbe74..d93fe12e12 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.")