Commit 1f503ebe authored by Julien Palard's avatar Julien Palard
Browse files

Clearer protocol for check.py allowing to print on success.

parent 4bbc0718
......@@ -52,10 +52,12 @@ Once received by a worker the worker runs two things:
whatever is needed).
- A `check.py` script is then started in a sandbox (no internet
connectivity, restricted filesystem, CPU, memory usage, …). This is
the script that check the student answer, the protocol is simple: if
the script prints, then then answer is wrong, and what's been
printed is displayed, as Markdown, to the student.
connectivity, restricted filesystem, CPU, memory usage, …).
This is the script that check the student answer, the protocol is
simple: if the script exits with non-zero, then then answer is
wrong. And what's been printed (both stdout and stderr) is
displayed, as Markdown, to the student. If the answer is right and
nothing is printed, a default congratulation message is used.
Both `pre_check.py` and `check.py` are in Python, but they're not
limited to check for Python answers, if you want to check for shell
......
......@@ -167,7 +167,7 @@ def check_answer_task(answer: dict):
prof_proc = Popen(
["firejail"]
+ FIREJAIL_OPTIONS
+ ["--private=" + tmpdir, "python3", "./check.py"],
+ ["--private=" + tmpdir, "python3", "-u", "./check.py"],
stdin=DEVNULL,
stdout=PIPE,
stderr=STDOUT,
......@@ -183,17 +183,15 @@ def check_answer_task(answer: dict):
'File "' + os.path.expanduser("~/"), 'File "'
)
)[:65_536]
if prof_proc.returncode == 0:
return True, stdout or congrats(answer.get("language", "en"))
if prof_proc.returncode == 255:
return False, "Checker timed out, look for infinite loops maybe?"
if prof_proc.returncode != 0 or stdout:
return False, stdout
return True, congrats(answer.get("language", "en"))
return False, stdout
except TimeoutExpired:
prof_proc.kill()
prof_proc.wait()
return False, "Checker timed out."
except OSError as err:
return str(err)
except MemoryError:
return False, "Not enough memory to run your code."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment