Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.write() clashes with nested bars on python 3.6 #398

Closed
staffanm opened this issue Jun 14, 2017 · 4 comments · Fixed by #464
Closed

.write() clashes with nested bars on python 3.6 #398

staffanm opened this issue Jun 14, 2017 · 4 comments · Fixed by #464
Assignees
Labels
p2-bug-warning ⚠ Visual output bad
Milestone

Comments

@staffanm
Copy link
Contributor

staffanm commented Jun 14, 2017

Starting with the example code given for nested progress bars, I've tried the following:

from tqdm import trange, tqdm
from time import sleep

for i in trange(10, desc='1st loop'):
    tqdm.write("%s" % i)
    for j in trange(5, desc='2nd loop', leave=False):
	tqdm.write("%s, %s" % (i, j))
        for k in trange(100, desc='3nd loop'):
            tqdm.write("%s, %s, %s" % (i,j,k))
            sleep(0.01)

Under python 2.7 this works as expected, the log messages are written above the three nested progress bars at the bottom of the console.

On python 3.6, the log messages appear to overwrite the progress bars, which are rapidly scrolled off-screen (by new log messages) as soon as they are updated.

Maybe this is related to #348 -- applying the patch suggested in #331 does not fix the problem, however.

This is on MacOS Sierra, using the stock Terminal app.

@duckythescientist
Copy link

It's a Python 3.5 issue as well. Even just the presence of a second bar will keep writes from being shown. Here is my minimized example:

from time import sleep
from tqdm import tqdm

def two_bars_with_surrounding_write():
    tqdm.write("starting")
    sleep(1)

    a = tqdm(total=10)
    b = tqdm(total=100)
    sleep(1)

    a.update()
    b.update()

    tqdm.write("finished")
    sleep(1)
    tqdm.write("finished again")
    sleep(1)

two_bars_with_surrounding_write()
"""starting text shows but neither finished text shows"""

Ubuntu 16.04 with Guake or stock terminal.

@staffanm
Copy link
Contributor Author

@duckythescientist Could you try the small change suggested in #399 and see if it fixes your problem? It seems to do that in my environment.

@duckythescientist
Copy link

@staffanm That fixes the problem when I have two progress bars and doing writes, but when I have one bar then do a write, the write works, but the bar disappears.

However, if I always self.fp.flush() instead of only when n is truthy, that fixes both problems.

@staffanm
Copy link
Contributor Author

Good catch @duckythescientist -- I've updated the PR accordingly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-bug-warning ⚠ Visual output bad
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants