Skip to content

Commit

Permalink
Merge pull request #22 from RangHo/issue-21
Browse files Browse the repository at this point in the history
[COR1010] 지원되는 환경에서만 시간 초과 기능 활성화
  • Loading branch information
RangHo authored Apr 8, 2024
2 parents b9cbadf + 6de4cf7 commit b620bd7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions COR1010/TA/grader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@
import re

# Signal library is only available on UNIX
if sys.platform != "win32":
if sys.platform == 'linux' or sys.platform == 'darwin':
import signal
def timeout_handler(signum, frame):
raise TimeoutError("Student's code timed out!")

def set_alarm(seconds: int):
signal.alarm(seconds)

signal.signal(signal.SIGALRM, timeout_handler)
else:
def set_alarm(seconds: int):
log_info("Timeout feature is not supported on this platform.")
log_info("Student's code will run indefinitely.")


from dataclasses import dataclass
from pathlib import Path
Expand Down Expand Up @@ -179,7 +187,7 @@ def run(script_path: Path, input_path: Optional[Path] = None) -> RunResult:
"""Run a script and return its output."""

# Set up an alarm
signal.alarm(5)
set_alarm(5)

# Of course, their code can set this computer on fire
try:
Expand Down Expand Up @@ -224,7 +232,7 @@ def run(script_path: Path, input_path: Optional[Path] = None) -> RunResult:
output_str="Timeout"
)
finally:
signal.alarm(0)
set_alarm(0)


if __name__ == '__main__':
Expand Down

0 comments on commit b620bd7

Please sign in to comment.