Skip to content

Commit f4eaf3d

Browse files
committed
nix-eval-jobs: add a 5m timeout
1 parent ce3be32 commit f4eaf3d

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

.github/eval.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""Evaluate flake outputs using nix-eval-jobs with index-based sharding."""
66

77
import json
8+
import select
89
import subprocess
910
import sys
1011
import time
@@ -42,6 +43,9 @@
4243
"""
4344

4445

46+
TIMEOUT_SECONDS = 300 # 5 minutes
47+
48+
4549
def run_eval(
4650
job_id: int, total_jobs: int
4751
) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
@@ -70,18 +74,35 @@ def run_eval(
7074
successes = []
7175
errors = []
7276
start_time = time.time()
77+
timed_out = False
7378

7479
with subprocess.Popen(
7580
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
7681
) as proc:
7782
assert proc.stdout is not None
78-
for line in proc.stdout:
83+
while True:
84+
elapsed = time.time() - start_time
85+
if elapsed > TIMEOUT_SECONDS:
86+
print(f"\n[{elapsed:6.1f}s] ⏱ Timeout after {TIMEOUT_SECONDS}s")
87+
proc.terminate()
88+
timed_out = True
89+
break
90+
91+
# Use select to avoid blocking indefinitely
92+
readable, _, _ = select.select([proc.stdout], [], [], 1.0)
93+
if not readable:
94+
continue
95+
96+
line = proc.stdout.readline()
97+
if not line:
98+
break # EOF
99+
79100
line = line.strip()
80101
if not line:
81102
continue
103+
82104
try:
83105
result = json.loads(line)
84-
elapsed = time.time() - start_time
85106
attr = result.get("attr", "?")
86107
if "error" in result:
87108
errors.append(result)
@@ -98,6 +119,9 @@ def run_eval(
98119

99120
proc.wait()
100121

122+
if timed_out:
123+
errors.append({"attr": "timeout", "error": f"Evaluation timed out after {TIMEOUT_SECONDS}s"})
124+
101125
return successes, errors
102126

103127

0 commit comments

Comments
 (0)