console-rs / indicatif

A command line progress reporting library for Rust
MIT License
4.43k stars 243 forks source link

ProgressBar does not get redrawn #212

Closed matthiasbeyer closed 4 years ago

matthiasbeyer commented 4 years ago

I have a multi-threaded program where I add a ProgressBar with length 100 to a multi bar and then continue to tick() and set_length() the bar (increasing values, as I see in the log output). The bar gets drawn when it initializes, but not afterwards until I finish() it.

How can I debug what's happening here?

Unfortunately, I cannot share the code. Hope you understand and that you can guide me through the process of debugging this anyways!

matthiasbeyer commented 4 years ago

After the finish() call, the bar gets drawn as complete, but it does not redraw the bar but draws a new bar instead. Maybe that's a hint for you what's happening here.

mibac138 commented 4 years ago

Do you call MultiProgress::join? When a ProgressBar is connected to a MultiProgress calling ProgressBar::tick sends new data to MultiProgress but the MultiProgress itself needs to be updated as well.

matthiasbeyer commented 4 years ago

I call MultiProgress::join after all threads that have a ProgressBar that was added to the multi-bar are finished (futures are awaited), yes.

matthiasbeyer commented 4 years ago

Do you mean I need to join while updating the progress bars?

mibac138 commented 4 years ago

Do you mean I need to join while updating the progress bars?

Yes, you need. That should fix the issue. Keep in mind that join blocks the thread until all ProgressBars have finished.

matthiasbeyer commented 4 years ago

It is really inconvenient that I have to manually wrap the MultiProgress object in an Arc and move it around, then.

matthiasbeyer commented 4 years ago

Hm, the longer I try, the more I get the impression that indicatif is not a good choice for async-await codebases.

matthiasbeyer commented 4 years ago

Okay, I fixed my issue. Thanks for your support!

flopacero commented 3 years ago

@matthiasbeyer what was your final approach to the problem?

matthiasbeyer commented 3 years ago

Calling MultiProgress::join().

flopacero commented 3 years ago

Right. There's no way around. Just need some tricks giving the blocking nature of MultiProgress::join Thanks!