Fix timeout not working (#218)

pull/5155/head
merwanehamadi 2023-07-30 19:05:09 -07:00 committed by GitHub
parent 3bd6f0d496
commit d93950e6d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -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: