mirror of
https://github.com/QingdaoU/JudgeServer.git
synced 2024-12-28 21:31:43 +00:00
优化逻辑
This commit is contained in:
parent
10b229970a
commit
02bad344e3
@ -31,9 +31,8 @@ class JudgeServerClient(object):
|
||||
def ping(self):
|
||||
return self._request(self.server_base_url + "/ping")
|
||||
|
||||
def judge(self, src, language_config, submission_id, max_cpu_time, max_memory, test_case_id, spj_version=None, spj_config=None):
|
||||
def judge(self, src, language_config, max_cpu_time, max_memory, test_case_id, spj_version=None, spj_config=None):
|
||||
data = {"language_config": language_config,
|
||||
"submission_id": submission_id,
|
||||
"src": src,
|
||||
"max_cpu_time": max_cpu_time,
|
||||
"max_memory": max_memory,
|
||||
@ -94,24 +93,24 @@ if __name__ == "__main__":
|
||||
}
|
||||
"""
|
||||
|
||||
client = JudgeServerClient(token="token", server_base_url="http://123.57.151.42:11235")
|
||||
client = JudgeServerClient(token="token", server_base_url="http://123.57.151.42:12358")
|
||||
print client.ping(), "\n\n"
|
||||
print client.compile_spj(src=c_spj_src, spj_version="1", spj_compile_config=c_lang_config["spj_compile"],
|
||||
test_case_id="spj"), "\n\n"
|
||||
|
||||
print client.judge(src=c_src, language_config=c_lang_config, submission_id="0",
|
||||
print client.judge(src=c_src, language_config=c_lang_config,
|
||||
max_cpu_time=1000, max_memory=1024 * 1024 * 128,
|
||||
test_case_id="normal"), "\n\n"
|
||||
|
||||
print client.judge(src=cpp_src, language_config=cpp_lang_config, submission_id="1",
|
||||
print client.judge(src=cpp_src, language_config=cpp_lang_config,
|
||||
max_cpu_time=1000, max_memory=1024 * 1024 * 128,
|
||||
test_case_id="normal"), "\n\n"
|
||||
|
||||
print client.judge(src=java_src, language_config=java_lang_config, submission_id="2",
|
||||
print client.judge(src=java_src, language_config=java_lang_config,
|
||||
max_cpu_time=1000, max_memory=1024 * 1024 * 1024,
|
||||
test_case_id="normal"), "\n\n"
|
||||
|
||||
print client.judge(src=c_src, language_config=c_lang_config, submission_id="3",
|
||||
print client.judge(src=c_src, language_config=c_lang_config,
|
||||
max_cpu_time=1000, max_memory=1024 * 1024 * 128,
|
||||
test_case_id="spj",
|
||||
spj_version="1", spj_config=c_lang_config["spj_config"]), "\n\n"
|
||||
|
17
compiler.py
17
compiler.py
@ -16,7 +16,7 @@ class Compiler(object):
|
||||
command = compile_config["compile_command"]
|
||||
exe_path = os.path.join(output_dir, compile_config["exe_name"])
|
||||
command = command.format(src_path=src_path, exe_dir=output_dir, exe_path=exe_path)
|
||||
compiler_out = os.path.join(output_dir, str(time.time()) + "-compiler.out")
|
||||
compiler_out = os.path.join(output_dir, "compiler.out")
|
||||
_command = command.split(" ")
|
||||
|
||||
result = _judger.run(max_cpu_time=compile_config["max_cpu_time"],
|
||||
@ -37,12 +37,13 @@ class Compiler(object):
|
||||
gid=LOW_PRIVILEDGE_GID)
|
||||
|
||||
if result["result"] != _judger.RESULT_SUCCESS:
|
||||
try:
|
||||
if os.path.exists(compiler_out):
|
||||
with open(compiler_out) as f:
|
||||
error = f.read().strip()
|
||||
os.remove(compiler_out)
|
||||
if error:
|
||||
raise CompileError(error)
|
||||
except Exception:
|
||||
raise CompileError("Compiler runtime error, info: %s" % json.dumps(result).decode("utf-8"))
|
||||
return exe_path
|
||||
os.remove(compiler_out)
|
||||
if error:
|
||||
raise CompileError(error)
|
||||
raise CompileError("Compiler runtime error, info: %s" % json.dumps(result).decode("utf-8"))
|
||||
else:
|
||||
os.remove(compiler_out)
|
||||
return exe_path
|
||||
|
@ -5,6 +5,7 @@ import hashlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import uuid
|
||||
|
||||
import web
|
||||
|
||||
@ -53,10 +54,11 @@ class JudgeServer(object):
|
||||
raise TokenVerificationFailed("token not set")
|
||||
return hashlib.sha256(t).hexdigest()
|
||||
|
||||
def judge(self, language_config, submission_id, src, max_cpu_time, max_memory, test_case_id,
|
||||
def judge(self, language_config, src, max_cpu_time, max_memory, test_case_id,
|
||||
spj_version=None, spj_config=None):
|
||||
# init
|
||||
compile_config = language_config["compile"]
|
||||
submission_id = str(uuid.uuid4())
|
||||
|
||||
with InitSubmissionEnv(JUDGER_WORKSPACE_BASE, submission_id=str(submission_id)) as submission_dir:
|
||||
src_path = os.path.join(submission_dir, compile_config["src_name"])
|
||||
|
Loading…
Reference in New Issue
Block a user