Wrapper around Tqdm pbar which be shared between thread.
| 173 | |
| 174 | |
| 175 | class _TqdmPbarAsync(EmptyTqdm): |
| 176 | """Wrapper around Tqdm pbar which be shared between thread.""" |
| 177 | |
| 178 | _tqdm_bars = [] |
| 179 | |
| 180 | def __init__(self, pbar): |
| 181 | super().__init__() |
| 182 | self._lock = tqdm_lib.tqdm.get_lock() |
| 183 | self._pbar = pbar |
| 184 | self._tqdm_bars.append(pbar) |
| 185 | |
| 186 | def update_total(self, n=1): |
| 187 | """Increment total pbar value.""" |
| 188 | with self._lock: |
| 189 | self._pbar.total += n |
| 190 | self.refresh() |
| 191 | |
| 192 | def update(self, n=1): |
| 193 | """Increment current value.""" |
| 194 | with self._lock: |
| 195 | self._pbar.update(n) |
| 196 | self.refresh() |
| 197 | |
| 198 | def refresh(self): |
| 199 | """Refresh all.""" |
| 200 | for pbar in self._tqdm_bars: |
| 201 | pbar.refresh() |
| 202 | |
| 203 | def clear(self): |
| 204 | """Remove the tqdm pbar from the update.""" |
| 205 | self._tqdm_bars.pop() |