When running MetaFlow Flows, tqdm
progress bars do not get displayed until the final iteration, which defeats the purpose of measuring progress. Is there a way to force MetaFlow to print out tqdm updates?
How to show tqdm progress in MetaFlow?
830 views Asked by crypdick At
2
There are 2 answers
0

crypdick's answer works for me, but the problem is that I'm also seeing info logging from other unrelated modules, which can be very noisy. Instead you can set up logging only for tqdm. I've also written a helper function you can use that will wrap up all the logic into one function:
import logging
from tqdm import tqdm
from tqdm.contrib.logging import tqdm_logging_redirect
def show_progress():
tqdm_logger = logging.getLogger('tqdm')
tqdm_logger.setLevel(logging.INFO)
tqdm.pandas()
return tqdm_logging_redirect()
Usage:
with show_progress():
df.progress_apply(...)
The problem is that
tqdm
writes to stderr, but MetaFlow hides output to stderr. The solution requires two tricks: using a context manager to redirecttqdm
outputs to a logger, and setting that logger to write to stderr.Example:
I also tried redirecting output directly to stdout (without the
tqdm_logging_redirect
context manager orlogging
) usingtqdm(range(n), file=sys.stdout)
but that did not work.