tqdm icon indicating copy to clipboard operation
tqdm copied to clipboard

tqdm shows an update on every iteration, even with miniter>1

Open mwouts opened this issue 2 years ago • 3 comments

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: tqdm

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)

mwouts avatar Feb 16 '23 16:02 mwouts

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'))

mwouts avatar Feb 19 '23 13:02 mwouts

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_miniters to True when miniters is changed to 1, otherwise we get updates on every iteration
  • remove dynamic_miniters from the documentation since it is an internal variable
  • add a note in the documentation that maxinterval has priority over miniters
  • and possibly also treat maxinterval=None or maxinterval=0 in the same way as maxinterval=float('inf') (personally I had tried to deactivate maxinterval using None first).

I could well contribute a PR for this, just let me know if you agree with the above.

mwouts avatar Feb 19 '23 13:02 mwouts

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.

tobias-kirschstein avatar Aug 01 '24 21:08 tobias-kirschstein