question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Progress bars for steps (integration of tqdm)

See original GitHub issue

Is there a way to use tqdm inside a step (especially a foreach task)? I want to have a progress bar for each parallel task. Currently I am only able to see progress bars when a task has already successfully finished.

metaflow_with_tqdm

I am not familiar how logging is handled in metaflow but here are some examples from tqdm that could be helpful to make the progress bar work: https://github.com/tqdm/tqdm/blob/master/examples/parallel_bars.py https://github.com/tqdm/tqdm/blob/master/examples/redirect_print.py

In general, it looks like messages are only printed when the task completed. This makes the use of tqdm pointless. Is there a way to immediately print to console?

Here is the source code for the example from the gif:

from metaflow import FlowSpec, step


class HelloFlow(FlowSpec):
    """
    A flow where Metaflow prints 'Hi'.

    Run this flow to validate that Metaflow is installed correctly.

    """
    @step
    def start(self):
        """
        This is the 'start' step. All flows must have a step named 'start' that
        is the first step in the flow.

        """
        print("HelloFlow is starting.")
        self.multi_processing = list(range(4))
        self.next(self.hello, foreach="multi_processing")

    @step
    def hello(self):
        """
        A step with parallel processing that should be monitored with tqdm.

        """

        from tqdm import tqdm
        from time import sleep
        from random import random

        interval = random() * 0.001
        for _ in tqdm(range(10000)):
            sleep(interval)

        self.next(self.join)

    @step
    def join(self, inputs):
        """
        Join our parallel branches and merge results.

        """

        self.next(self.end)

    @step
    def end(self):
        """
        This is the 'end' step. All flows must have an 'end' step, which is the
        last step in the flow.

        """

        print("HelloFlow is all done.")


if __name__ == '__main__':
    HelloFlow()

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
crk-codaiocommented, Dec 12, 2019

Sorry for not having an update on this. We are looking into it internally and seeing if there is a way we can make this work. From the screencast you’ve pasted, clearly the log lines from tqdm are:

  1. Getting buffered (and hence seeing it later)
  2. Not seeing updates of progress - this is the one I need to spend more time debugging if there is a way to make it work with our log buffering + multiprocessing solution.
2reactions
crk-codaiocommented, Dec 6, 2019

Thank you for the very elaborate description (with screencasts 😃) Will take a look and get back to you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Track your loop using tqdm: 7 ways progress bars in Python ...
Track the your Python loops with a real-time progress bar. 4th one is intersting. tqdm is a Python library used for creating smart...
Read more >
Progress bars for Python with tqdm - Towards Data Science
The resulting tqdm progress bar gives us information that includes the task completion percentage, number of iterations complete, time elapsed, ...
Read more >
Progress Bars in Python with tqdm for Fun and Profit
In Arabic, tqdm (taqadum) means progress, and it is used to create a smart progress bar for the loops. You just need to...
Read more >
How to create a Python terminal progress bar using tqdm?
Tqdm bars can also be used to indicate the progress of nested loops. Multiple bars indicating the progress of each of the loops...
Read more >
python - Multiprocessing : use tqdm to display a progress bar
How can one display a progress bar that indicates at which step the 'map' function is ? from multiprocessing import Pool import tqdm...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found