捕获部分异常并转化为为JudgeClientError

This commit is contained in:
virusdefender 2016-10-02 02:15:49 +08:00
parent 083ded3f60
commit 67420ef0af
2 changed files with 22 additions and 10 deletions

View File

@ -57,7 +57,7 @@ class JudgeClient(object):
try:
f = open(user_output_file, "r")
except Exception:
return None, False
raise JudgeClientError("output not found")
output_md5 = hashlib.md5(f.read().rstrip()).hexdigest()
return output_md5, output_md5 == self._test_case_info["test_cases"][str(test_case_file_id)]["striped_output_md5"]
@ -80,7 +80,6 @@ class JudgeClient(object):
seccomp_rule_so_path=self._seccomp_rule_path(self._spj_config["seccomp_rule"]),
uid=LOW_PRIVILEDGE_UID,
gid=LOW_PRIVILEDGE_GID)
print result
if result["result"] == _judger.RESULT_SUCCESS or \
(result["result"] == _judger.RESULT_RUNTIME_ERROR and result["exit_code"] in [SPJ_WA, SPJ_ERROR]):
@ -120,8 +119,6 @@ class JudgeClient(object):
raise JudgeClientError("spj_config or spj_version not set")
spj_result = self._spj(in_file_path=in_file, user_out_file_path=out_file)
print "spj_result", spj_result
if spj_result == SPJ_WA:
run_result["result"] = WA
elif spj_result == SPJ_ERROR:

View File

@ -14,7 +14,7 @@ import web
from compiler import Compiler
from config import JUDGER_WORKSPACE_BASE, TEST_CASE_DIR
from exception import TokenVerificationFailed, CompileError, SPJCompileError
from exception import TokenVerificationFailed, CompileError, SPJCompileError,JudgeClientError
from judge_client import JudgeClient
DEBUG = os.environ.get("judger_debug") == "1"
@ -25,13 +25,21 @@ class InitSubmissionEnv(object):
self.path = os.path.join(judger_workspace, submission_id)
def __enter__(self):
os.mkdir(self.path)
os.chmod(self.path, 0777)
try:
os.mkdir(self.path)
os.chmod(self.path, 0777)
except Exception as e:
logging.exception(e)
raise JudgeClientError("failed to create runtime dir")
return self.path
def __exit__(self, exc_type, exc_val, exc_tb):
if not DEBUG:
shutil.rmtree(self.path, ignore_errors=True)
try:
shutil.rmtree(self.path)
except Exception as e:
logging.exception(e)
raise JudgeClientError("failed to clean runtime dir")
class JudgeServer(object):
@ -106,7 +114,11 @@ class JudgeServer(object):
if token != self._token:
raise TokenVerificationFailed("invalid token")
if web.data():
data = json.loads(web.data())
try:
data = json.loads(web.data())
except Exception as e:
logging.info(web.data())
return {"ret": "ServerError", "data": "invalid json"}
else:
data = {}
@ -117,7 +129,7 @@ class JudgeServer(object):
elif web.ctx["path"] == "/compile_spj":
callback = self.compile_spj
else:
return json.dumps({"err": "invalid-method", "data": None})
return json.dumps({"err": "InvalidMethod", "data": None})
return json.dumps({"err": None, "data": callback(**data)})
except Exception as e:
logging.exception(e)
@ -136,6 +148,9 @@ urls = (
if not os.environ.get("judger_token"):
raise TokenVerificationFailed("token not set")
if DEBUG:
logging.info("DEBUG=ON")
app = web.application(urls, globals())
wsgiapp = app.wsgifunc()