pb icon indicating copy to clipboard operation
pb copied to clipboard

MultiBar only works with threads

Open njaard opened this issue 6 years ago • 3 comments

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.

njaard avatar Nov 20 '17 10:11 njaard

I'm currently trying to get it working with rayon, we'll see if I'm successful.

fosskers avatar Dec 12 '20 02:12 fosskers

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.

fosskers avatar Dec 12 '20 02:12 fosskers

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.

fosskers avatar Dec 12 '20 03:12 fosskers