diff --git a/pl_sandbox/settings.py b/pl_sandbox/settings.py index 553f5f2..c68e8ce 100644 --- a/pl_sandbox/settings.py +++ b/pl_sandbox/settings.py @@ -12,12 +12,10 @@ import logging import os -import shutil -import sys import threading import time +import platform -import docker from sandbox.container import initialise_container @@ -58,6 +56,11 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Logger information +LOGGER_ADDRESS = '/dev/log' +if platform.system() == 'Darwin': + # https://docs.python.org/3/library/logging.handlers.html#sysloghandler + LOGGER_ADDRESS = '/var/run/syslog' + LOGGING = { 'version' : 1, 'disable_existing_loggers': False, @@ -91,7 +94,7 @@ 'level' : 'INFO', 'class' : 'logging.handlers.SysLogHandler', 'facility' : 'local6', - 'address' : '/dev/log', + 'address' : LOGGER_ADDRESS, 'formatter': 'verbose', 'filters' : ['require_debug_false'], }, @@ -99,7 +102,7 @@ 'level' : 'DEBUG', 'class' : 'logging.handlers.SysLogHandler', 'facility' : 'local6', - 'address' : '/dev/log', + 'address' : LOGGER_ADDRESS, 'formatter': 'verbose', 'filters' : ['require_debug_true'], }, diff --git a/requirements.txt b/requirements.txt index c3c5c16..7f8427a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ Django>=2.1.0,<3.0.0 docker pytz requests -timeout-decorator +wrapt_timeout_decorator \ No newline at end of file diff --git a/sandbox/executor.py b/sandbox/executor.py index a985f9a..f4b2765 100644 --- a/sandbox/executor.py +++ b/sandbox/executor.py @@ -5,11 +5,11 @@ import time import traceback -import timeout_decorator from django.conf import settings from sandbox.enums import SandboxErrCode from sandbox.exceptions import ContextNotFoundError, GraderError +from wrapt_timeout_decorator import * logger = logging.getLogger(__name__) @@ -118,7 +118,7 @@ def get_context(self): return j - @timeout_decorator.timeout(BUILD_TIMEOUT, use_signals=False) + @timeout(BUILD_TIMEOUT, use_signals=False) def build(self): """Execute builder.py.""" start = time.time() @@ -210,7 +210,7 @@ def get_context(self): return j - @timeout_decorator.timeout(EVAL_TIMEOUT, use_signals=False) + @timeout(EVAL_TIMEOUT, use_signals=False) def evaluate(self): """Execute grader.py, returning the result. """ start = time.time()