修改判题端的部分 bug
This commit is contained in:
@@ -58,7 +58,7 @@ class JudgeClient(object):
|
|||||||
# todo 系统调用白名单 chroot等参数
|
# todo 系统调用白名单 chroot等参数
|
||||||
command = "lrun" + \
|
command = "lrun" + \
|
||||||
" --max-cpu-time " + str(self._max_cpu_time / 1000.0) + \
|
" --max-cpu-time " + str(self._max_cpu_time / 1000.0) + \
|
||||||
" --max-real-time " + str(self._max_real_time / 1000.0) + \
|
" --max-real-time " + str(self._max_real_time / 1000.0 * 2) + \
|
||||||
" --max-memory " + str(self._max_memory * 1000 * 1000) + \
|
" --max-memory " + str(self._max_memory * 1000 * 1000) + \
|
||||||
" --network false" + \
|
" --network false" + \
|
||||||
" --uid " + str(lrun_uid) + \
|
" --uid " + str(lrun_uid) + \
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from settings import judger_workspace, mongodb_config
|
|||||||
# 参数有 -solution_id -time_limit -memory_limit -test_case_id
|
# 参数有 -solution_id -time_limit -memory_limit -test_case_id
|
||||||
# 获取到的值是['xxx.py', '-solution_id', '1111', '-time_limit', '1000', '-memory_limit', '100', '-test_case_id', 'aaaa']
|
# 获取到的值是['xxx.py', '-solution_id', '1111', '-time_limit', '1000', '-memory_limit', '100', '-test_case_id', 'aaaa']
|
||||||
args = sys.argv
|
args = sys.argv
|
||||||
solution_id = args[2]
|
submission_id = args[2]
|
||||||
time_limit = args[4]
|
time_limit = args[4]
|
||||||
memory_limit = args[6]
|
memory_limit = args[6]
|
||||||
test_case_id = args[8]
|
test_case_id = args[8]
|
||||||
@@ -23,23 +23,32 @@ test_case_id = args[8]
|
|||||||
connection = pymongo.MongoClient(host=mongodb_config["host"], port=mongodb_config["port"])
|
connection = pymongo.MongoClient(host=mongodb_config["host"], port=mongodb_config["port"])
|
||||||
collection = connection["oj"]["oj_submission"]
|
collection = connection["oj"]["oj_submission"]
|
||||||
|
|
||||||
submission = collection.find_one({"_id": ObjectId(solution_id)})
|
submission = collection.find_one({"_id": ObjectId(submission_id)})
|
||||||
if not submission:
|
if not submission:
|
||||||
exit()
|
exit()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
# 将代码写入文件
|
# 将代码写入文件
|
||||||
language = languages[submission["language"]]
|
language = languages[submission["language"]]
|
||||||
src_path = judger_workspace + "run/" + language["src_name"]
|
src_path = judger_workspace + "run/" + language["src_name"]
|
||||||
f = open(src_path, "w")
|
f = open(src_path, "w")
|
||||||
f.write(submission["code"])
|
f.write(submission["code"].encode("utf8"))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# 编译
|
# 编译
|
||||||
try:
|
try:
|
||||||
exe_path = compile_(language, src_path, judger_workspace + "run/")
|
exe_path = compile_(language, src_path, judger_workspace + "run/")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print {"result": result["compile_error"]}
|
print e
|
||||||
|
connection = pymongo.MongoClient(host=mongodb_config["host"], port=mongodb_config["port"])
|
||||||
|
collection = connection["oj"]["oj_submission"]
|
||||||
|
data = {"result": result["compile_error"], "info": str(e)}
|
||||||
|
collection.find_one_and_update({"_id": ObjectId(submission_id)}, {"$set": data})
|
||||||
|
connection.close()
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
print "Compile successfully"
|
||||||
|
# 运行
|
||||||
try:
|
try:
|
||||||
client = JudgeClient(language_code=submission["language"],
|
client = JudgeClient(language_code=submission["language"],
|
||||||
exe_path=exe_path,
|
exe_path=exe_path,
|
||||||
@@ -47,9 +56,23 @@ try:
|
|||||||
max_real_time=int(time_limit) * 2,
|
max_real_time=int(time_limit) * 2,
|
||||||
max_memory=int(memory_limit),
|
max_memory=int(memory_limit),
|
||||||
test_case_dir=judger_workspace + "test_case/" + test_case_id + "/")
|
test_case_dir=judger_workspace + "test_case/" + test_case_id + "/")
|
||||||
print client.run()
|
judge_result = {"result": result["accepted"], "info": client.run()}
|
||||||
|
|
||||||
|
for item in judge_result["info"]:
|
||||||
|
if item["result"]:
|
||||||
|
judge_result["result"] = item["result"]
|
||||||
|
break
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print e
|
print e
|
||||||
print {"result": result["system_error"]}
|
judge_result = {"result": result["system_error"], "info": str(e)}
|
||||||
|
|
||||||
|
print "Run successfully"
|
||||||
|
print judge_result
|
||||||
|
connection = pymongo.MongoClient(host=mongodb_config["host"], port=mongodb_config["port"])
|
||||||
|
collection = connection["oj"]["oj_submission"]
|
||||||
|
collection.find_one_and_update({"_id": ObjectId(submission_id)}, {"$set": judge_result})
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ def judge(solution_id, time_limit, memory_limit, test_case_id):
|
|||||||
"python judger/run.py "
|
"python judger/run.py "
|
||||||
"--solution_id %s --time_limit %s --memory_limit %s --test_case_id %s" %
|
"--solution_id %s --time_limit %s --memory_limit %s --test_case_id %s" %
|
||||||
(solution_id, str(time_limit), str(memory_limit), test_case_id),
|
(solution_id, str(time_limit), str(memory_limit), test_case_id),
|
||||||
# 如果设置的最长运行时间小于1000毫秒,那么/1000就是0,处理一下这个情况,设置为两秒
|
# 设置最长运行时间是3倍的 cpu 时间
|
||||||
timeout=(time_limit / 1000 * 3) or 2, shell=True)
|
timeout=(time_limit / 1000.0 * 3), shell=True)
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
print "docker timeout"
|
print "docker timeout"
|
||||||
|
|||||||
Reference in New Issue
Block a user