Skip to content

tqdm.write() overwrite closed nested progress bar #719

@Hiestaa

Description

@Hiestaa

I have looked around for a solution to this problem with no success. I have found issue #398 which seems to report a similar issue, but the problem there is related to open nested progress bars. My issue has to do with the tqdm.write() calls after the progress bar is closed. More details below:

Versions

  • TQDM v4.31.1
  • Python v3.6.8
  • OS: MacOSX Mojave v10.14.3 (18D42)
  • sys.version: 3.6.8 (default, Apr 17 2019, 10:09:55) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.3)]

Description

I am running into a nested progress bar clobbering issue when using tqdm.write() past the closing of the progress bar. Here is a minimal code example to reproduce the issue:

import time
from tqdm import trange, tqdm

for x in trange(5):
    for y in trange(5):
        time.sleep(0.01)
        tqdm.write('x={}, y={}'.format(x, y))


tqdm.write('x' * 50)
tqdm.write('x' * 50)

Here is the output I'm seeing in the terminal after the process is complete

x=0, y=0
x=0, y=1
x=0, y=2
x=0, y=3
x=0, y=4
x=1, y=0
x=1, y=1
x=1, y=2
x=1, y=3
x=1, y=4
x=2, y=0
x=2, y=1
x=2, y=2
x=2, y=3
x=2, y=4
x=3, y=0
x=3, y=1
x=3, y=2
x=3, y=3
x=3, y=4
x=4, y=0
x=4, y=1
x=4, y=2
x=4, y=3
x=4, y=4
100%|█████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 17.10it/s]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx████████████| 5/5 [00:00<00:00, 85.86it/s]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  • Expected behavior: The first line of xxxxxxx.... should be printed after the closed nested progress bar.
  • Actual behavior: The first line of xxxxx.... clobbers the completed and closed progress bar, resulting in less than ideal and quite confusing log output.

Additional notes:

  • if using 3 or more nested progress bars, only the first progress bar will be remain intact. All subsequent, closed progress bar will be clobbered. Example output from slightly modified code above to include a third nested loop:
x=4, y=3, z=4
x=0, y=4, z=0
x=1, y=4, z=1
x=2, y=4, z=2
x=3, y=4, z=3
x=4, y=4, z=4
100%|█████████████████████████████████████████████████████████| 5/5 [00:01<00:00,  3.43it/s]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx████████████| 5/5 [00:00<00:00, 17.21it/s]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx████████████| 5/5 [00:00<00:00, 86.46it/s]
  • Using manual creation and closing of the progress bar (with pbar = tqdm(range(5), total=5) and pbar.close()) did not change the behaviour (not that it should be)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions