pb
pb copied to clipboard
MultiBar only works with threads
The only way to display multiple progress bars is to use threads, this requirement isn't documented, and when you use single threads, you get silent failures.
I'm currently trying to get it working with rayon
, we'll see if I'm successful.
The following prints nothing, not even the DONE!
messages:
pub(crate) fn bar_test() {
let mb = Arc::new(MultiBar::new());
std::thread::spawn({
let mb = Arc::clone(&mb);
move || {
mb.listen();
}
});
(0..30).into_par_iter().for_each(|n| {
let mut bar = mb.create_bar(100);
bar.message(&format!("{} ", n));
for _ in 0..100 {
bar.inc();
std::thread::sleep(Duration::from_millis(50));
}
bar.finish_print("DONE!");
})
}
The process does complete and exit, which means the loops are occuring, but the bars seem to be lost.
If I add a second mb.listen()
after the for_each
loop, the DONEs all get printed in bulk after the entire thing exits. PR #92 mentions that bars can be created dynamically after the listen
has been initiated, but that doesn't seem to work in this case.