This is a very common use case when you need to globally disable all tqdm
's output, desirably without changing the code in all places where it is used and which you probably do not control.
Starting version 4.66.0
Set environment variable TQDM_DISABLE=1
.
Note that exact value of the variable does not matter, it just should be a non-empty string.
Older versions
Users need to patch tqdm in order to stop polluting logs. One of the shortest ways I found is probably this:
from tqdm import tqdm
from functools import partialmethod
tqdm.__init__ = partialmethod(tqdm.__init__, disable=True)
The idea is defaulting the already supported (but not sufficient) parameter of the initializer. It is not sufficient because you need to add it in each place where tqdm is instantiated, which you don't want, that's why we modify __init__
to make such a default.
The patch works independently of the order of imports and will affect all subsequently created tqdm
objects.