diff options
Diffstat (limited to 'tqdm/contrib/concurrent.py')
-rw-r--r-- | tqdm/contrib/concurrent.py | 37 |
1 files changed, 6 insertions, 31 deletions
diff --git a/tqdm/contrib/concurrent.py b/tqdm/contrib/concurrent.py index ccb5e12..cd81d62 100644 --- a/tqdm/contrib/concurrent.py +++ b/tqdm/contrib/concurrent.py @@ -1,32 +1,13 @@ """ Thin wrappers around `concurrent.futures`. """ -from __future__ import absolute_import - from contextlib import contextmanager +from operator import length_hint +from os import cpu_count from ..auto import tqdm as tqdm_auto from ..std import TqdmWarning -try: - from operator import length_hint -except ImportError: - def length_hint(it, default=0): - """Returns `len(it)`, falling back to `default`""" - try: - return len(it) - except TypeError: - return default -try: - from os import cpu_count -except ImportError: - try: - from multiprocessing import cpu_count - except ImportError: - def cpu_count(): - return 4 -import sys - __author__ = {"github.com/": ["casperdcl"]} __all__ = ['thread_map', 'process_map'] @@ -64,16 +45,10 @@ def _executor_map(PoolExecutor, fn, *iterables, **tqdm_kwargs): chunksize = kwargs.pop("chunksize", 1) lock_name = kwargs.pop("lock_name", "") with ensure_lock(tqdm_class, lock_name=lock_name) as lk: - pool_kwargs = {'max_workers': max_workers} - sys_version = sys.version_info[:2] - if sys_version >= (3, 7): - # share lock in case workers are already using `tqdm` - pool_kwargs.update(initializer=tqdm_class.set_lock, initargs=(lk,)) - map_args = {} - if not (3, 0) < sys_version < (3, 5): - map_args.update(chunksize=chunksize) - with PoolExecutor(**pool_kwargs) as ex: - return list(tqdm_class(ex.map(fn, *iterables, **map_args), **kwargs)) + # share lock in case workers are already using `tqdm` + with PoolExecutor(max_workers=max_workers, initializer=tqdm_class.set_lock, + initargs=(lk,)) as ex: + return list(tqdm_class(ex.map(fn, *iterables, chunksize=chunksize), **kwargs)) def thread_map(fn, *iterables, **tqdm_kwargs): |