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

tqdm progress bar flashes when writing lots of text #280

Closed
ahallrq opened this issue Oct 6, 2016 · 4 comments
Closed

tqdm progress bar flashes when writing lots of text #280

ahallrq opened this issue Oct 6, 2016 · 4 comments
Labels
question/docs ‽ Documentation clarification candidate

Comments

@ahallrq
Copy link

ahallrq commented Oct 6, 2016

I've noticed when using tqdm that using tqdm.write() really quickly (such as in a loop) causes the bar itself to flash wildly.

As an example, consider the following code:

import tqdm

for i in tqdm.trange(1000000):
    tqdm.tqdm.write(i)

It prints the number correctly however the bar flashes to the point where it's near unreadable unless you add a delay. This is really annoying since I wish to print lots on information while running the bar.

Is this due to limitations in how tqdm draws the bar or some other issue?

EDIT: Almost forgot, I'm using Python3, tqdm 4.8.4 on Arch Linux, if that's important. The terminal I was using was xfce4-terminal with zsh

@lrq3000 lrq3000 added question/docs ‽ Documentation clarification candidate p0-bug-critical ☢ Exception rasing p3-enhancement 🔥 Much new such feature and removed p0-bug-critical ☢ Exception rasing p3-enhancement 🔥 Much new such feature labels Oct 6, 2016
@lrq3000
Copy link
Member

lrq3000 commented Oct 6, 2016

Hello @iownall555,

TLDR: yes it's normal, it's by design and we hope this scenario won't happen in practical cases.

Long version:
Yes that's normal, it's because tqdm doesn't use curses, so it needs to clear the progress bar to then write the message and then write the progress bar on a new line. With curses, we could move the progress bar to a newline without clearing it first, but with a big cost with environment compatibility.

All that is to say that .write() is not meant to be used in a tight loop: it's meant to display warnings or errors or important messages to the user, which usually mean that these messages are meant to be few (if you show a gazillion messages, a human user cannot possibly register them in their consciousness).

We could workaround this problem by implementing a pooling system: tqdm could memorize the messages and display them at once every few seconds (or any other reasonable timeframe, for example based on mininterval), but this design was avoided until now because we thought it was better to immediately display messages: important messages should be shown ASAP, tqdm should not decide when to show them, it should be the responsibility of the user.

So yeah, maybe we could provide an optional pooling system, but I'm not sure it will ever be useful. If you have so many messages to print at the same time as the progress bar, you probably ought to print them in a log anyway.

@ahallrq
Copy link
Author

ahallrq commented Oct 6, 2016

That explains it perfectly. I'll try to keep message to a minimum as per your suggestion since using curses in my script (my use-case was for compiling lots of Lua files to bytecode) seems like overkill.

Thanks for the explanation about this.

@ahallrq ahallrq closed this as completed Oct 6, 2016
@lrq3000
Copy link
Member

lrq3000 commented Oct 7, 2016

You are welcome :)
Le 7 Oct. 2016 00:56, "iownall555" notifications@github.com a écrit :

That explains it perfectly. I'll try to keep message to a minimum as per
your suggestion since using curses in my script (my use-case was for
compiling lots of Lua files to bytecode) seems like overkill.

Thanks for the explanation about this.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#280 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABES3tc3SspiKljPSqqgPK6gqYziOX4eks5qxXyMgaJpZM4KPhgs
.

@softmarshmallow
Copy link

softmarshmallow commented Jun 8, 2023

It's very ambiguous. What is "many"? In what factor does my terminal starts to blink? what if I spend hours to add pooling system and it still blinks?

For my case, I have dozens or pbars and 10 messages (write) per second. I don't consider this as "many" updates, though the pbar part is always flashing and unable to read the content. (I use this many pbars to track tasks per each threads)

I understand this is a pickly issue, but still we deserve more documented and expected behavoiuour out of this library.

Thank you : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question/docs ‽ Documentation clarification candidate
Projects
None yet
Development

No branches or pull requests

3 participants