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
Add tick
to MultiProgress to complement join
#132
Conversation
97ad3c8
to
e272e90
Compare
I am in need of a fix for #33 asap. Will this make it into a new release soon? |
@dan-da If you want to you can modify your |
@mibac138 hey thanks. I just tried with your branch, but nothing displays, same as with 0.14.0. I am just creating a MultiProgress with 3 ProgressBar+style and then calling set_position on each, in a single thread Any chance you can provide a working single-threaded example? Also, I tried to call MultiProgress::tick() just to see if it helps, but it requires a progress::TickTimeLimit and indacitif::progress is private. btw, my particular use-case is like the download example, except I want to show: |
@dan-da I'm not sure what is it that doesn't work for you but I've written a simple example below: use indicatif::{MultiProgress, ProgressBar, TickTimeLimit};
use rand::Rng;
fn main() {
let mpb = MultiProgress::new();
let pb1 = mpb.add(ProgressBar::new(30));
let pb2 = mpb.add(ProgressBar::new(30));
let mut rng = rand::thread_rng();
for _ in 0..10 {
thread::sleep(Duration::from_secs(1));
pb1.set_position(rng.gen_range(0, 30));
pb2.set_position(rng.gen_range(0, 30));
mpb.tick(TickTimeLimit::Indefinite);
}
} |
It is working great now. Thx for the example. I was missing the tick() call. |
hmm, I do have one display prob. I'm not sure if it's a problem with the lib, or my usage of it. So I have two progress bars with {elapsed_precise} in the template, and one bar (A) is updated more frequently with a new position (via set_position()) than the other (B). After each update, which occurs every 500 milliseconds, tick() is called on the MultiProgress that contains both, with a 50ms Duration. The issue is that the elapsed seconds in A sometimes update before B. Usually they are in sync, each second, but not always. I'm not sure if TickTimeLimit::Timeout is supposed to work like ProgressBar::enable_steady_tick()? I just want the elapsed time to update in unison for both bars each time. If above is not clear, here's a simplified version of my update func, which is invoked from a long-running process.
edit: I did a bit more testing, setting the sleep to 2000, and two things become clear:
|
@dan-da I believe this might be due to the refresh rate of your draw target. Try changing how you created |
hi, yeah I've tried with stderr_nohz(), and I also tried creating a thread that calls MultiProgress::tick() every 10ms. Neither approach causes the elapsed_precise clock to tick each second as desired. Here is a test case that demonstrates the issue, with a for loop that is updating the progress bars every 2 seconds, and the clock also updates every 2 secs.
|
* Changed `joining` field of `MultiProgress` from `AtomicBool` to `Mutex`. Because the internal `join_impl` can now be called multiple times I figured it's better to use a Mutex as it automatically unlocks preventing panics "bricking" the progress bar. * Because MultiProgress can contain multiple child progress bars I feel like the meaning of a single tick isn't really clear. Just a single state update (`self.rx.recv()`) seems too small. Because of that I allow the user to configure how long do they want a tick to last adding greater flexibility. * Made `is_done` public to let the user know whether they still need to invoke `tick`
Indicatif MultiProgress doesn't work well in the static context This is basically a workaround for that. A regular thread is spawned to update the progress in the background. Note that the code might be refactored to the way it was before. Once console-rs/indicatif#132 is merged.
Indicatif MultiProgress doesn't work well in the static context This is basically a workaround for that. A regular thread is spawned to update the progress in the background. Note that the code might be refactored to the way it was before. Once console-rs/indicatif#132 is merged.
Indicatif MultiProgress doesn't work well in the static context This is basically a workaround for that. A regular thread is spawned to update the progress in the background. Note that the code might be refactored to the way it was before. Once console-rs/indicatif#132 is merged.
Closed without comment on the test case I posted? |
This pull is working for me for single threaded MultiProgress. Is there anything blocking it being merged? elapsed_precise is working https://github.com/etrombly/dropcutter |
I don't think this is necessary with current main, but if still is feel free to open a new issue/PR. |
joining
field ofMultiProgress
fromAtomicBool
toMutex
.Because the internal
join_impl
can now be called multiple timesI figured it's better to use a Mutex as it automatically unlocks
preventing panics "bricking" the progress bar.
like the meaning of a single tick isn't really clear. Just a single
state update (
self.rx.recv()
) seems too small. Because of that Iallow the user to configure how long do they want a tick to last
adding greater flexibility.
is_done
public to let the user know whether they still needto invoke
tick
Fixes #33, seems like fixes #125