skmap.parallel.utils.ThreadGeneratorLazy#
- ThreadGeneratorLazy(worker, args, max_workers=4, chunk=8, fixed_args=())[source]#
Execute a function in parallel using a
ThreadPoolExecutor[1].- Parameters:
worker (
Callable) – Function to execute in parallel.args (
Iterator[tuple]) – Argument iterator where each element is send job of the pool.max_workers (
int) – Number of CPU cores to use in the parallelization. By default all cores are used.chunk (
int) – Number of chunks to split the parallelization jobs.fixed_args (
tuple) – Constant arguments added inargsin each execution of theworkerfunction.
- Returns:
A generator with the return of all workers
- Return type:
Generator
References
[1] Python ThreadPoolExecutor class
Examples
>>> from skmap.parallel import ThreadGeneratorLazy >>> >>> def worker(i, msg): ... print(f'{i}: {msg}') ... return f'Worker {i} finished' >>> >>> args = iter([ (i,) for i in range(0,5)]) >>> fixed_args = ("I'm running in parallel", ) >>> >>> for result in ThreadGeneratorLazy(worker, args, fixed_args=fixed_args): ... print(result)