tqdm
tqdm copied to clipboard
tqdm shows an update on every iteration, even with miniter>1
Hello, thanks for the great library!
I am using tqdm==4.64.1 with python==3.10.8 on linux.
I see an issue with miniter, that is consistent with other reports at #1396 and #1381 (and I also tried to change dynamic_miniters but that one only seems to exist in the documentation, cf #1327).
The issue is that, while I have miniter=240, the first update is displayed for i=200, and then I get an update for ever iteration:

This is a script that reproduces the issue:
import sys
from tqdm import tqdm, __version__
from time import sleep
print(__version__, sys.version, sys.platform)
N = 100000
progress_bar = tqdm(range(N), total=N, miniters=240)
# actual = this prints an update at i~180 and then for every iteration on
# expected = update at i=239, 479, etc
for i in progress_bar:
sleep(0.1)
progress_bar.set_postfix({'i':i}, refresh=False)
There seems to be an issue in the combination of miniters with maxinterval. At least when I set maxinterval=float('inf') I have the expected updates at i=239, 479, 719 etc:
progress_bar = tqdm(range(N), total=N, miniters=240, maxinterval=float('inf'))
I think the issue is caused by this paragraph: https://github.com/tqdm/tqdm/blob/6791e8c5b3d6c30bdd2060c346996bfb5a6f10d1/tqdm/_monitor.py#L74-L84
I think we should
- set
dynamic_miniterstoTruewhenminitersis changed to 1, otherwise we get updates on every iteration - remove
dynamic_minitersfrom the documentation since it is an internal variable - add a note in the documentation that
maxintervalhas priority overminiters - and possibly also treat
maxinterval=Noneormaxinterval=0in the same way asmaxinterval=float('inf')(personally I had tried to deactivatemaxintervalusingNonefirst).
I could well contribute a PR for this, just let me know if you agree with the above.
I had the same issue and was very confused by that. The way Marc described it makes more sense to me than the current implementation, so I second changing it as proposed.