Kill all subprocesses (#265)

Co-authored-by: merwanehamadi <merwanehamadi@gmail.com>
This commit is contained in:
Erik Peterson
2023-08-06 21:12:10 -07:00
committed by GitHub
parent db48e7849b
commit fa8f010e80

View File

@@ -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.")