Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite progress bar #72

Open
frankenjoe opened this issue Jul 1, 2022 · 0 comments
Open

Infinite progress bar #72

frankenjoe opened this issue Jul 1, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@frankenjoe
Copy link
Collaborator

frankenjoe commented Jul 1, 2022

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

@frankenjoe frankenjoe added the enhancement New feature or request label Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant