Skip to content

Commit 4bf7a71

Browse files
committed
add the ability to customize --max-duration
1 parent 301ef6e commit 4bf7a71

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

tool/AOC.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ def run(argv: list[str]) -> None:
100100
action="store_true",
101101
default=False,
102102
)
103+
parser.add_argument(
104+
"--max-duration",
105+
help="max duration per script in seconds (default to 1s)",
106+
default=1,
107+
type=int
108+
)
103109

104110
args = parser.parse_args(argv)
105111

@@ -115,6 +121,7 @@ def run(argv: list[str]) -> None:
115121
args.restricted,
116122
args.expand,
117123
args.times,
124+
args.max_duration,
118125
)
119126

120127
@staticmethod

tool/run.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@
1717
from tool.leaderboard.leaderboard import generate_leaderboard
1818

1919

20-
def maxDurationHandler(signum, frame):
21-
raise Exception("Maxiumum of 1s reached")
22-
23-
signal.signal(signal.SIGALRM, maxDurationHandler)
24-
25-
26-
2720
class DifferentAnswersException(Exception):
2821
pass
2922

3023

3124
class UnexpectedDebugLinesException(Exception):
3225
pass
3326

27+
def maxDurationHandler(signum, frame):
28+
raise Exception("Too long")
29+
30+
signal.signal(signal.SIGALRM, maxDurationHandler)
31+
3432

3533
def run(
3634
days: list[int] | None,
@@ -44,6 +42,7 @@ def run(
4442
restricted: bool,
4543
expand: bool,
4644
print_time_dist: bool,
45+
max_duration: int,
4746
) -> None:
4847
problems = discovery.get_problems(days, parts, all_days_parts)
4948
printed_day_header: set[int] = set()
@@ -71,7 +70,7 @@ def run(
7170
if restricted and input.author != submission.author.split(".")[0]:
7271
continue
7372
try:
74-
signal.alarm(1) # Start the 1s timer
73+
signal.alarm(max_duration) # Start timeout timer
7574
result = run_submission(
7675
problem, submission, input, previous, no_debug
7776
)
@@ -82,7 +81,7 @@ def run(
8281
except (DifferentAnswersException, UnexpectedDebugLinesException) as e:
8382
errors.append(f"{BColor.RED}ERROR: {e}{BColor.ENDC}")
8483
except Exception:
85-
errors.append(f"{BColor.RED}[{submission.author}] day-{submission.problem.day}/part-{submission.problem.part} ({submission.language}){BColor.ENDC}: Maxiumum of 1s reached (on input {BColor.BLUE}{input.author}{BColor.ENDC})")
84+
errors.append(f"{BColor.RED}[{submission.author}] day-{submission.problem.day}/part-{submission.problem.part} ({submission.language}){BColor.ENDC}: Maximum of {max_duration}s reached (on input {BColor.BLUE}{input.author}{BColor.ENDC})")
8685

8786
for submission in submissions:
8887
if submission.runnable is not None:

0 commit comments

Comments
 (0)