def spawn_server(config, rep_addr, pub_addr, nb_players, sockets_dir,
opts, file_opts):
# Build command
cmd = [config['path']['stechec_server'],
"--rules", config['path']['rules'],
"--rep_addr", rep_addr,
"--pub_addr", pub_addr,
"--nb_clients", str(nb_players),
"--time", "3000",
"--socket_timeout", "45000",
"--dump", "/box/dump.json",
"--verbose", "1"]
if opts is not None:
cmd += opts
if file_opts is not None:
fopts, tmp_files = create_file_opts(file_opts)
cmd.extend(fopts)
# Create the isolator
limits = {'wall-time': config['timeout'].get('server', 400)}
isolator = isolate.Isolator(
limits, allowed_dirs=['/var', '/tmp', sockets_dir + ':rw'])
async with isolator:
# Run the isolated server
await isolator.run(cmd, merge_outputs=True)
# Retrieve the dump and gz-compress it
try:
dump_path = isolator.path / 'dump.json'
with dump_path.open('rb') as dump:
gzdump = gzip.compress(dump.read())
except FileNotFoundError:
raise_isolate_error("server: dump.json was not created.\n", cmd,
isolator)
# Retrieve the output
output = get_output(isolator)
if isolator.isolate_retcode != 0:
raise_isolate_error("server: exited with a non-zero code", cmd,
isolator)
return output, gzdump
评论列表
文章目录