Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
Fix Auto-GPT never timing out
Browse files Browse the repository at this point in the history
Signed-off-by: Merwane Hamadi <[email protected]>
  • Loading branch information
waynehamadi committed Jul 11, 2023
1 parent 4ecb70c commit 40117a1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
50 changes: 30 additions & 20 deletions agbenchmark/agent_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,45 @@ def run_agent(
)

start_time = time.time()
timeout = config["cutoff"]

while True:
if process.stdout is None:
continue
print(
f"Running Python function '{config['entry_path']}' with timeout {config['cutoff']}"
)
command = [sys.executable, "-m", config["entry_path"], str(task)]
process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
)

while output := process.stdout.readline():
print(output.strip())
start_time = time.time()

# Check if process has ended
if process.poll() is not None:
print("The Python function has finished running.")
break
while True:
output = ""
if process.stdout is not None:
output = process.stdout.readline()
print(output.strip())

# Check if process has exceeded timeout
if time.time() - start_time > timeout:
print(
"The Python function has exceeded the time limit and was terminated."
)
# Terminate the process group
process.terminate()
# 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 > config["cutoff"])
):
break

# Optional: sleep for a while
time.sleep(0.1)
if time.time() - start_time > config["cutoff"]:
print("The Python function has exceeded the time limit and was terminated.")
process.kill()
else:
print("The Python function has finished running.")

# Wait for process to terminate, then get return code
process.wait()

if process.returncode != 0:
print(f"The agent timed out")


def copy_artifacts_into_workspace(
workspace: str, artifact_folder_name: str, challenge_dir_path: str
Expand Down
2 changes: 1 addition & 1 deletion agent/Auto-GPT

0 comments on commit 40117a1

Please sign in to comment.