Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/tqdm/dask.py @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 68:5028fdace37b |
---|---|
1 from functools import partial | |
2 | |
3 from dask.callbacks import Callback | |
4 | |
5 from .auto import tqdm as tqdm_auto | |
6 | |
7 __author__ = {"github.com/": ["casperdcl"]} | |
8 __all__ = ['TqdmCallback'] | |
9 | |
10 | |
11 class TqdmCallback(Callback): | |
12 """Dask callback for task progress.""" | |
13 def __init__(self, start=None, pretask=None, tqdm_class=tqdm_auto, | |
14 **tqdm_kwargs): | |
15 """ | |
16 Parameters | |
17 ---------- | |
18 tqdm_class : optional | |
19 `tqdm` class to use for bars [default: `tqdm.auto.tqdm`]. | |
20 tqdm_kwargs : optional | |
21 Any other arguments used for all bars. | |
22 """ | |
23 super().__init__(start=start, pretask=pretask) | |
24 if tqdm_kwargs: | |
25 tqdm_class = partial(tqdm_class, **tqdm_kwargs) | |
26 self.tqdm_class = tqdm_class | |
27 | |
28 def _start_state(self, _, state): | |
29 self.pbar = self.tqdm_class(total=sum( | |
30 len(state[k]) for k in ['ready', 'waiting', 'running', 'finished'])) | |
31 | |
32 def _posttask(self, *_, **__): | |
33 self.pbar.update() | |
34 | |
35 def _finish(self, *_, **__): | |
36 self.pbar.close() | |
37 | |
38 def display(self): | |
39 """Displays in the current cell in Notebooks.""" | |
40 container = getattr(self.bar, 'container', None) | |
41 if container is None: | |
42 return | |
43 from .notebook import display | |
44 display(container) |