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.

Fix timeout not working (#218)

merwanehamadid93950e6d999
diff --git a/agbenchmark/agent_interface.py b/agbenchmark/agent_interface.py
index 177d391432..4087151ab9 100644
--- a/agbenchmark/agent_interface.py
+++ b/agbenchmark/agent_interface.py
@@ -1,4 +1,5 @@
import os
+import select
import shutil
import subprocess
import sys
@@ -33,6 +34,7 @@ def run_agent(
timeout = 100000
print(f"Running '{entry_path}' with timeout {timeout}")
+
command = [sys.executable, "-m", entry_path, str(task)]
process = subprocess.Popen(
command,
@@ -40,22 +42,20 @@ def run_agent(
stderr=subprocess.STDOUT,
universal_newlines=True,
cwd=HOME_DIRECTORY,
+ bufsize=1,
)
start_time = time.time()
while True:
- output = ""
- if process.stdout is not None:
+
+ # This checks if there's data to be read from stdout without blocking.
+ if process.stdout and select.select([process.stdout], [], [], 0)[0]:
output = process.stdout.readline()
print(output.strip())
# Check if process has ended, has no more output, or exceeded timeout
- if (
- process.poll() is not None
- or output == ""
- or (time.time() - start_time > timeout)
- ):
+ if process.poll() is not None or (time.time() - start_time > timeout):
break
if time.time() - start_time > timeout: