Comments (1)
I improved thread_map's behaviour to made it more like imap_unordered's progress output:
from concurrent.futures import ThreadPoolExecutor
def _executor_map(PoolExecutor, fn, *iterables, **tqdm_kwargs):
"""
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].
"""
from tqdm.contrib.concurrent import ensure_lock, length_hint, tqdm_auto, cpu_count
kwargs = tqdm_kwargs.copy()
if "total" not in kwargs:
kwargs["total"] = length_hint(iterables[0])
tqdm_class = kwargs.pop("tqdm_class", tqdm_auto)
max_workers = kwargs.pop("max_workers", min(32, cpu_count() + 4))
chunksize = kwargs.pop("chunksize", 1)
lock_name = kwargs.pop("lock_name", "")
with ensure_lock(tqdm_class, lock_name=lock_name) as lk:
# share lock in case workers are already using `tqdm`
with PoolExecutor(max_workers=max_workers, initializer=tqdm_class.set_lock,
initargs=(lk,)) as ex:
with tqdm_class(**kwargs) as pbar:
orisubmit = ex.submit
def patchsubmit(*args, **kwargs):
fut = orisubmit(*args, **kwargs)
fut.add_done_callback(lambda _: pbar.update())
return fut
ex.submit = patchsubmit
return list(ex.map(fn, *iterables, chunksize=chunksize))
thread_map = lambda fn, *iterables, **tqdm_kwargs: _executor_map(ThreadPoolExecutor, fn, *iterables, **tqdm_kwargs)
from tqdm.
Related Issues (20)
- move readme to tqdm.github.io
- TQDM as ??????? and multiline in the terminal of EC2 machine
- Using asyncio on jupyter notebook
- Proposal: setting of info, without needing `pbar` object
- Docs Issue: `dynamic_miniters` mentioned, but not in tqdm arg list
- progress_map on panda's index
- Multiprocessing - Progress bar not updating for starmap
- Unexpected behavior when combining `initial` and `range` as iterator. HOT 5
- `DummyTqdmFile.write` cannot handle bytes type
- TMonitor thread remains active after tqdm closes HOT 1
- Allow option to run the loop at a specified slower rate
- No direct link to online documentation in README file
- Jupyter-notebook: bar freezes then updates after a while
- what's the decent way to update `desc` and `postfix` HOT 6
- Update prints a new line each call
- Add wrapper for functions that are called repeatedly
- unable to set format for numbers with unit_scale
- Allow providing `OrderedDict` to the option `postfix` in the `tqdm` class
- Filters are removed when inside logging_redirect_tqdm context
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tqdm.