Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is there a way to globally disable all tqdm progress bars?

Something like the NO_COLOR environement variable?

These progress bars are nice when you launched a single loop yourself, but when you are running an automated battery of many things they become annoying and pollute your terminal too much. I know that you can silence each particular program that uses tqdm by setting a 'disable' option. But this requires editing the python source code of the program.



Something like this should work:

    import os
    import sys
    from tqdm import tqdm as _tqdm

    def tqdm(*args, **kwargs):
        try:
            disable = bool(int(os.environ['NO_PROGRESSBARS']))
        except KeyError:
            disable = not sys.stdout.isatty()
        except (ValueError, TypeError):
            disable = False
        kwargs.setdefault('disable', disable)
        return _tqdm(*args, **kwargs)
Then import that instead of tqdm.tqdm.

sys.stdout.isatty() isn't a perfect answer to what people ask when they want to know "am I running in an automated environment, or is a human user looking at my output?", but it's close. More nuance is available online.


Thanks for the answer!

> import that instead of tqdm.tqdm

But it's not me who is importing tqdm to begin with! I call many programs in parallel from shell scripts (out of my control) and they all call tqdm individually. I need to stop tqdm output from outside these programs.

Your code should be part of tqdm itself, not written by individual programmers.

> am I running in an automated environment, or is a human user looking at my output?

But I want to stop tqdm output precisely because I'm a human looking at it. If you have more than one or two progress bars simultaneously, it becomes useless clutter.

As much as I like to use tqdm myself for my programs, I'm sad that as tqdm becomes more and more popular, my terminal output becomes more and more cluttered, to an absurd amount. Piping the output to a file does not help and is totally the wrong idea. I'm precisely interested in seeing--in real time--the part of the output that does not come from tqdm, such as warnings and errors.


That's a reasonable request. Discussion about a feature along those lines seems to be happening in https://github.com/tqdm/tqdm/issues/614; perhaps you could weigh in there?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: