parallel
======== Parallel ========
This module simplifies the use of multiprocessing. It provides a single
function, :func:run_parallel
, that runs a function in parallel over a list of
arguments.
is_notebook() -> bool
Are we running code in a jupyter notebook?
Code from https://stackoverflow.com/a/39662359
Source code in src/rra_tools/parallel.py
run_parallel(runner: Callable[[T1], T2], arg_list: Collection[T1], *, num_cores: int = 1, progress_bar: bool = False, notebook_fallback: bool = True) -> list[T2]
Runs a single argument function in parallel over a list of arguments.
This function dodges multiprocessing if only a single process is requested to make functions more flexible to debugging. It also supports progress bars if requested.
Parameters
runner
A single argument function to be run in parallel.
arg_list
A list of arguments to be run over in parallel.
num_cores
Maximum number of processes to be run in parallel. If num_cores == 1,
The jobs will be run serially without invoking multiprocessing.
progress_bar
Whether to display a progress bar for the running jobs.
notebook_fallback
Whether to fallback to standard multiprocessing in a notebook. We use pathos
for multiprocessing as it uses a more robust serialization library, but pathos
has some leaky state and doesn't properly close down child processes when
interrupted in a jupyter notebook.
Returns
List[Any] A list of the results of the parallel calls of the runner.