Skip to content

Commit e955d3c

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

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
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: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
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

@@ -44,6 +37,7 @@ def run(
4437
restricted: bool,
4538
expand: bool,
4639
print_time_dist: bool,
40+
max_duration: int,
4741
) -> None:
4842
problems = discovery.get_problems(days, parts, all_days_parts)
4943
printed_day_header: set[int] = set()
@@ -71,7 +65,11 @@ def run(
7165
if restricted and input.author != submission.author.split(".")[0]:
7266
continue
7367
try:
74-
signal.alarm(1) # Start the 1s timer
68+
def maxDurationHandler(signum, frame):
69+
raise Exception(f"Maxiumum of {max_duration}s reached")
70+
71+
signal.signal(signal.SIGALRM, maxDurationHandler)
72+
signal.alarm(max_duration) # Start timeout timer
7573
result = run_submission(
7674
problem, submission, input, previous, no_debug
7775
)

0 commit comments

Comments
 (0)