mirror of
https://github.com/QingdaoU/JudgeServer.git
synced 2025-09-26 22:31:25 +08:00
增加Python设置
This commit is contained in:
parent
bd40ce6f9f
commit
1880d857e8
@ -6,7 +6,7 @@ import json
|
||||
|
||||
import requests
|
||||
|
||||
from languages import c_lang_config, cpp_lang_config, java_lang_config, c_lang_spj_config, c_lang_spj_compile
|
||||
from languages import c_lang_config, cpp_lang_config, java_lang_config, c_lang_spj_config, c_lang_spj_compile, py2_lang_config
|
||||
|
||||
|
||||
class JudgeServerClientError(Exception):
|
||||
@ -92,8 +92,17 @@ if __name__ == "__main__":
|
||||
}
|
||||
"""
|
||||
|
||||
py2_src = """s = raw_input()
|
||||
s1 = s.split(" ")
|
||||
print int(s1[0]) + int(s1[1])"""
|
||||
|
||||
client = JudgeServerClient(token="token", server_base_url="http://123.57.151.42:12358")
|
||||
print client.ping(), "\n\n"
|
||||
|
||||
print client.judge(src=py2_src, language_config=py2_lang_config,
|
||||
max_cpu_time=1000, max_memory=128 * 1024 * 1024,
|
||||
test_case_id="normal"), "\n\n"
|
||||
|
||||
print client.compile_spj(src=c_spj_src, spj_version="1", spj_compile_config=c_lang_spj_compile,
|
||||
test_case_id="spj"), "\n\n"
|
||||
|
||||
|
@ -32,7 +32,6 @@ c_lang_spj_config = {
|
||||
}
|
||||
|
||||
cpp_lang_config = {
|
||||
"name": "cpp",
|
||||
"compile": {
|
||||
"src_name": "main.cpp",
|
||||
"exe_name": "main",
|
||||
@ -62,4 +61,20 @@ java_lang_config = {
|
||||
"seccomp_rule": None,
|
||||
"env": ["MALLOC_ARENA_MAX=1"]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
py2_lang_config = {
|
||||
"compile": {
|
||||
"src_name": "solution.py",
|
||||
"exe_name": "solution.pyc",
|
||||
"max_cpu_time": 3000,
|
||||
"max_real_time": 5000,
|
||||
"max_memory": 128 * 1024 * 1024,
|
||||
"compile_command": "/usr/bin/python -m py_compile {src_path}",
|
||||
},
|
||||
"run": {
|
||||
"command": "/usr/bin/python {exe_path}",
|
||||
"seccomp_rule": None,
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ class Compiler(object):
|
||||
max_real_time=compile_config["max_real_time"],
|
||||
max_memory=compile_config["max_memory"],
|
||||
max_output_size=1024 * 1024,
|
||||
max_process_number=20,
|
||||
max_process_number=_judger.UNLIMITED,
|
||||
exe_path=_command[0],
|
||||
# /dev/null is best, but in some system, this will call ioctl system call
|
||||
input_path=src_path,
|
||||
|
24
server.py
24
server.py
@ -57,20 +57,26 @@ class JudgeServer(object):
|
||||
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"]
|
||||
compile_config = language_config.get("compile")
|
||||
run_config = language_config["run"]
|
||||
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"])
|
||||
if compile_config:
|
||||
src_path = os.path.join(submission_dir, compile_config["src_name"])
|
||||
|
||||
# write source code into file
|
||||
with open(src_path, "w") as f:
|
||||
f.write(src.encode("utf-8"))
|
||||
# write source code into file
|
||||
with open(src_path, "w") as f:
|
||||
f.write(src.encode("utf-8"))
|
||||
|
||||
# compile source code, return exe file path
|
||||
exe_path = Compiler().compile(compile_config=compile_config,
|
||||
src_path=src_path,
|
||||
output_dir=submission_dir)
|
||||
# compile source code, return exe file path
|
||||
exe_path = Compiler().compile(compile_config=compile_config,
|
||||
src_path=src_path,
|
||||
output_dir=submission_dir)
|
||||
else:
|
||||
exe_path = os.path.join(submission_dir, run_config["exe_path"])
|
||||
with open(exe_path, "w") as f:
|
||||
f.write(src.encode("utf-8"))
|
||||
|
||||
judge_client = JudgeClient(run_config=language_config["run"],
|
||||
exe_path=exe_path,
|
||||
|
Loading…
Reference in New Issue
Block a user