async def _init(): parallelism = config.get('parallelism', 1) logger.info('Using parallelism: %d', parallelism) for sandbox in await create_sandboxes(parallelism): _sandbox_pool.put_nowait(sandbox) try: with open(_LANGS_FILE) as file: langs_config = yaml.load(file, Loader=yaml.RoundTripLoader) except FileNotFoundError: logger.error('Language file %s not found.', _LANGS_FILE) exit(1) for lang_name, lang_config in langs_config.items(): if lang_config['type'] == 'compiler': compiler = Compiler(lang_config['compiler_file'], shlex.split(lang_config['compiler_args']), lang_config['code_file'], lang_config['execute_file'], shlex.split(lang_config['execute_args'])) _langs[lang_name] = partial( _compiler_build, compiler, time_limit_ns=lang_config.get('time_limit_ms', DEFAULT_TIME_MS) * 1000000, memory_limit_bytes=lang_config.get('memory_limit_kb', DEFAULT_MEM_KB) * 1024, process_limit=lang_config.get('process_limit', PROCESS_LIMIT)) elif lang_config['type'] == 'interpreter': interpreter = Interpreter(lang_config['code_file'], lang_config['execute_file'], shlex.split(lang_config['execute_args'])) _langs[lang_name] = partial(_interpreter_build, interpreter) else: logger.error('Unknown type %s', lang_config['type'])
async def update_problem_data(session): logger.info('Update problem data') result = await session.judge_datalist(config.get('last_update_at', 0)) for pid in result['pids']: await cache_invalidate(pid['domain_id'], str(pid['pid'])) logger.debug('Invalidated %s/%s', pid['domain_id'], str(pid['pid'])) config['last_update_at'] = result['time'] await save_config()
def _init(): parallelism = config.get('parallelism', 2) if parallelism < 2: logger.warning( 'Parallelism less than 2, custom judge will not be supported.') logger.info('Using parallelism: %d', parallelism) sandboxes_task = create_sandboxes(parallelism) global _lock, _queue _lock = Lock() _queue = LifoQueue() put_sandbox(*get_event_loop().run_until_complete(sandboxes_task))