Implementation of `thread_map` and `process_map`. Parameters ---------- tqdm_class : [default: tqdm.auto.tqdm]. max_workers : [default: min(32, cpu_count() + 4)]. chunksize : [default: 1]. lock_name : [default: "":str].
(PoolExecutor, fn, *iterables, **tqdm_kwargs)
| 27 | |
| 28 | |
| 29 | def _executor_map(PoolExecutor, fn, *iterables, **tqdm_kwargs): |
| 30 | """ |
| 31 | Implementation of `thread_map` and `process_map`. |
| 32 | |
| 33 | Parameters |
| 34 | ---------- |
| 35 | tqdm_class : [default: tqdm.auto.tqdm]. |
| 36 | max_workers : [default: min(32, cpu_count() + 4)]. |
| 37 | chunksize : [default: 1]. |
| 38 | lock_name : [default: "":str]. |
| 39 | """ |
| 40 | kwargs = tqdm_kwargs.copy() |
| 41 | if "total" not in kwargs: |
| 42 | kwargs["total"] = length_hint(iterables[0]) |
| 43 | tqdm_class = kwargs.pop("tqdm_class", tqdm_auto) |
| 44 | max_workers = kwargs.pop("max_workers", min(32, cpu_count() + 4)) |
| 45 | chunksize = kwargs.pop("chunksize", 1) |
| 46 | lock_name = kwargs.pop("lock_name", "") |
| 47 | with ensure_lock(tqdm_class, lock_name=lock_name) as lk: |
| 48 | # share lock in case workers are already using `tqdm` |
| 49 | with PoolExecutor(max_workers=max_workers, initializer=tqdm_class.set_lock, |
| 50 | initargs=(lk,)) as ex: |
| 51 | return list(tqdm_class(ex.map(fn, *iterables, chunksize=chunksize), **kwargs)) |
| 52 | |
| 53 | |
| 54 | def thread_map(fn, *iterables, **tqdm_kwargs): |
no test coverage detected