pool.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:jd4 作者: vijos 项目源码 文件源码
def _compiler_build(compiler, code,
                          time_limit_ns, memory_limit_bytes, process_limit):
    loop = get_event_loop()
    sandbox = await _sandbox_pool.get()
    try:
        await compiler.prepare(sandbox, code.encode())
        output_file = path.join(sandbox.in_dir, 'output')
        mkfifo(output_file)
        with socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK) as cgroup_sock:
            cgroup_sock.bind(path.join(sandbox.in_dir, 'cgroup'))
            cgroup_sock.listen()
            build_task = loop.create_task(compiler.build(
                sandbox,
                output_file='/in/output',
                cgroup_file='/in/cgroup'))
            others_task = gather(read_pipe(output_file, _MAX_OUTPUT),
                                 wait_cgroup(cgroup_sock,
                                             build_task,
                                             time_limit_ns,
                                             memory_limit_bytes,
                                             process_limit))
            package, status = await build_task
            output, (time_usage_ns, memory_usage_bytes) = await others_task
        return package, output.decode(encoding='utf-8', errors='replace'), \
               time_usage_ns, memory_usage_bytes
    finally:
        _sandbox_pool.put_nowait(sandbox)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号