-
Notifications
You must be signed in to change notification settings - Fork 243
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
bug: MultiProgress
with insert_before
and suspend
destroys the previous progress bars
#594
Comments
^ Ignore this brainfart please |
Ok that does make sense. Yes that is basically my use case, however, I was putting |
Ah.... actually, sorry, I took another look and my explanation from before was wrong.
The issue is that your The solution is to just extend the lifetime of all the use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
fn main() {
let m = MultiProgress::new();
let sty = ProgressStyle::with_template(
"{prefix:<10} [{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}",
)
.unwrap()
.progress_chars("##-");
let mut pbs = vec![];
let total = m.add(ProgressBar::new(10));
total.set_style(sty.clone());
total.set_prefix("total");
for i in 0..10 {
let name = format!("item-{i}");
let pb = m.insert_before(&total, ProgressBar::new(100));
pbs.push(pb.clone());
pb.set_style(sty.clone());
pb.set_prefix(name);
for _ in 0..100 {
total.suspend(|| ());
pb.inc(1);
}
pb.finish();
total.inc(1);
}
total.finish();
} |
If you'd like to avoid the manual |
The whole |
Oh that is awesome, yeah that does seem to fix use case (though it might still be desirable to skip suspend when i can). Thanks for taking a stab at that and finding a solution! Follow up question. Why doesn't the the Multiprogress bar keep the individual Arc's around by doing a clone into a inner vec itself (thus keeping ref count a 1) and keeping the old bars around? |
Sure thing!
It's a trade-off. We want to be able to redraw as much as possible in the case of a call to Perhaps we could add an option for BTW for some additional context, see: |
Do we already have good documentation for the constraints here? I feel like the |
That's fair. It is not well documented, but I submitted an issue to do so: #595 |
I noticed that when i added the
suspend
function to my cargo-like multi progress bar it kept deleting previous progress bars.env:
cargo toml:
After narrowing down the issue i found that it only happened if I used the
insert_before
or theinsert_at
function. The regularadd
did not cause this.it gives the output of:
removing the suspend call gives me the expected output of:
When i ran it with add, instead of
insert_before
it printed correctly both ways (expect the total is at the top rather than bottom hence why i wanted to useinsert_before
. I also tried usingpb.suspend()
instead oftotal.suspend()
but got the same results.Thanks!
The text was updated successfully, but these errors were encountered: