Skip to content

Infinite progress bar #72

Open
Open
@frankenjoe

Description

@frankenjoe

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

image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions