Skip to content

Restting progress bar counter requires refresh for all new updates. #547

@abaisero

Description

@abaisero

Hi all, first of all thank you for the effort you've put into developing this useful tool.

I was trying to reset a progress bar to its initial state, and I found what I think might be a bug. Resetting the progress bar state to a previous value has been discussed here: #545 #432 #374 . The consensus seems to be that to reset a progress bar, you need to explicitly set its n attribute and then refresh manually:

pbar.n = 0;
pbar.refresh()

However I've found that, even doing this, the progress bar will not update correctly until its counter reaches the previous value again.

Here is a MWE:

from tqdm import tqdm
import time

total = 100
pbar = tqdm(total=total)

for i in range(10):
    pbar.update()
    time.sleep(.1)

pbar.n = 0
pbar.refresh()

for i in range(total):
    pbar.update()
    time.sleep(.1)

Expected behavior:

  1. Bar grows from 0% to 10%
  2. Bar resets to 0%
  3. Bar grows from 0% to 100%

Actual behavior:

  1. Bar grows from 0% to 10%
  2. Bar resets to 0%
  3. Bar stays at 0% for about the same time that it would take to reach 10%
  4. Bar goes instantly to 10%, and then grows from 10% to 100%

The issue doesn't present itself if I manually refresh after each update in the second loop; but I assume this is a work-around and should not be necessary (?)

system: Debian GNU/Linux 9.4 (stretch)
python: 3.6.5
tqdm: 4.19.8

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions