Equivalent of `list(map(fn, *iterables))` driven by `concurrent.futures.ProcessPoolExecutor`. Parameters ---------- tqdm_class : optional `tqdm` class to use for bars [default: tqdm.auto.tqdm]. max_workers : int, optional Maximum number of workers to spawn
(fn, *iterables, **tqdm_kwargs)
| 70 | |
| 71 | |
| 72 | def process_map(fn, *iterables, **tqdm_kwargs): |
| 73 | """ |
| 74 | Equivalent of `list(map(fn, *iterables))` |
| 75 | driven by `concurrent.futures.ProcessPoolExecutor`. |
| 76 | |
| 77 | Parameters |
| 78 | ---------- |
| 79 | tqdm_class : optional |
| 80 | `tqdm` class to use for bars [default: tqdm.auto.tqdm]. |
| 81 | max_workers : int, optional |
| 82 | Maximum number of workers to spawn; passed to |
| 83 | `concurrent.futures.ProcessPoolExecutor.__init__`. |
| 84 | [default: min(32, cpu_count() + 4)]. |
| 85 | chunksize : int, optional |
| 86 | Size of chunks sent to worker processes; passed to |
| 87 | `concurrent.futures.ProcessPoolExecutor.map`. [default: 1]. |
| 88 | lock_name : str, optional |
| 89 | Member of `tqdm_class.get_lock()` to use [default: mp_lock]. |
| 90 | """ |
| 91 | from concurrent.futures import ProcessPoolExecutor |
| 92 | if iterables and "chunksize" not in tqdm_kwargs: |
| 93 | # default `chunksize=1` has poor performance for large iterables |
| 94 | # (most time spent dispatching items to workers). |
| 95 | longest_iterable_len = max(map(length_hint, iterables)) |
| 96 | if longest_iterable_len > 1000: |
| 97 | from warnings import warn |
| 98 | warn("Iterable length %d > 1000 but `chunksize` is not set." |
| 99 | " This may seriously degrade multiprocess performance." |
| 100 | " Set `chunksize=1` or more." % longest_iterable_len, |
| 101 | TqdmWarning, stacklevel=2) |
| 102 | if "lock_name" not in tqdm_kwargs: |
| 103 | tqdm_kwargs = tqdm_kwargs.copy() |
| 104 | tqdm_kwargs["lock_name"] = "mp_lock" |
| 105 | return _executor_map(ProcessPoolExecutor, fn, *iterables, **tqdm_kwargs) |
nothing calls this directly
no test coverage detected