Open
Description
Sometimes it would be nice to show a progress bar without a determined loop. E.g.:
with audeer.progress_bar(...):
some_heavy_job()
Unfortunately, this use case seems not to be supported out of the box with tqdm
. What is supported is setting total=float('inf')
. Here's a first rough implementation of an infinite progress bar:
class InfiniteProgressBar:
def __init__(
self,
desc: str,
):
self.desc = desc
self.abort = False
self.thread = threading.Thread(target=self._show)
def __enter__(self):
self.abort = False
self.thread.start()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.abort = True
self.thread.join()
self.thread = None
def _show(self):
def infinite():
while True:
yield
with audeer.progress_bar(
infinite(),
desc='Description',
total=float('inf'),
) as pbar:
while not self.abort:
time.sleep(1)
pbar.update()
with InfiniteProgressBar('Description'):
time.sleep(5) # some job
What's not nice yet is that it's not showing any progress. Would be nice to have something like here: visionmedia/node-progress#121