def get_reusable_executor(max_workers=None, context=None, timeout=<NUM_LIT:10>,<EOL>kill_workers=False, reuse="<STR_LIT>",<EOL>job_reducers=None, result_reducers=None,<EOL>initializer=None, initargs=()):
with _executor_lock:<EOL><INDENT>global _executor, _executor_kwargs<EOL>executor = _executor<EOL>if max_workers is None:<EOL><INDENT>if reuse is True and executor is not None:<EOL><INDENT>max_workers = executor._max_workers<EOL><DEDENT>else:<EOL><INDENT>max_workers = cpu_count()<EOL><DEDENT><DEDENT>elif max_workers <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>.format(max_workers))<EOL><DEDENT>if isinstance(context, STRING_TYPE):<EOL><INDENT>context = get_context(context)<EOL><DEDENT>if context is not None and context.get_start_method() == "<STR_LIT>":<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>kwargs = dict(context=context, timeout=timeout,<EOL>job_reducers=job_reducers,<EOL>result_reducers=result_reducers,<EOL>initializer=initializer, initargs=initargs)<EOL>if executor is None:<EOL><INDENT>mp.util.debug("<STR_LIT>"<EOL>.format(max_workers))<EOL>executor_id = _get_next_executor_id()<EOL>_executor_kwargs = kwargs<EOL>_executor = executor = _ReusablePoolExecutor(<EOL>_executor_lock, max_workers=max_workers,<EOL>executor_id=executor_id, **kwargs)<EOL><DEDENT>else:<EOL><INDENT>if reuse == '<STR_LIT>':<EOL><INDENT>reuse = kwargs == _executor_kwargs<EOL><DEDENT>if (executor._flags.broken or executor._flags.shutdown<EOL>or not reuse):<EOL><INDENT>if executor._flags.broken:<EOL><INDENT>reason = "<STR_LIT>"<EOL><DEDENT>elif executor._flags.shutdown:<EOL><INDENT>reason = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>reason = "<STR_LIT>"<EOL><DEDENT>mp.util.debug(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>.format(max_workers, reason))<EOL>executor.shutdown(wait=True, kill_workers=kill_workers)<EOL>_executor = executor = _executor_kwargs = None<EOL>return get_reusable_executor(max_workers=max_workers,<EOL>**kwargs)<EOL><DEDENT>else:<EOL><INDENT>mp.util.debug("<STR_LIT>"<EOL>.format(executor._max_workers))<EOL>executor._resize(max_workers)<EOL><DEDENT><DEDENT><DEDENT>return executor<EOL>
Return the current ReusableExectutor instance.

    Start a new instance if it has not been started already or if the previous
    instance was left in a broken state.

    If the previous instance does not have the requested number of workers, the
    executor is dynamically resized to adjust the number of workers prior to
    returning.

    Reusing a singleton instance spares the overhead of starting new worker
    processes and importing common python packages each time.

    ``max_workers`` controls the maximum number of tasks that can be running in
    parallel in worker processes. By default this is set to the number of
    CPUs on the host.

    Setting ``timeout`` (in seconds) makes idle workers automatically shutdown
    so as to release system resources. New workers are respawn upon submission
    of new tasks so that ``max_workers`` are available to accept the newly
    submitted tasks. Setting ``timeout`` to around 100 times the time required
    to spawn new processes and import packages in them (on the order of 100ms)
    ensures that the overhead of spawning workers is negligible.

    Setting ``kill_workers=True`` makes it possible to forcibly interrupt
    previously spawned jobs to get a new instance of the reusable executor
    with new constructor argument values.

    The ``job_reducers`` and ``result_reducers`` are used to customize the
    pickling of tasks and results send to the executor.

    When provided, the ``initializer`` is run first in newly spawned
    processes with argument ``initargs``.