Closed rawhuul closed 4 months ago
Can you turn this into a minimal reproduction that doesn't have any dependencies other than indicatif?
Yeah sure.
Here is the code,
use indicatif::{ProgressBar, ProgressStyle};
use rayon::prelude::*;
fn waiting(pb: &ProgressBar, n: i32) -> i32 {
std::thread::sleep(std::time::Duration::from_secs(10));
pb.inc(1);
n * n
}
fn main() {
let st = ProgressStyle::with_template("{spinner:.bold} ({pos}/{len}) {msg}").unwrap();
let pb = ProgressBar::new(4 as u64);
pb.set_style(st);
pb.set_message("Syncing buckets from the remote...");
let v = (1..4)
.into_par_iter()
.map(|n| waiting(&pb, n))
.collect::<Vec<_>>();
println!("{v:#?}");
}
Cargo.toml
:
[package]
name = "indi"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
indicatif = { version = "0.17.6", features = ["rayon"] }
rayon = "1.7.0"
Results:
https://github.com/console-rs/indicatif/assets/84739019/f241efb5-60bc-485b-a52a-d1397d7fbf01
As you can see spinner is stuck and only spins after function returns, whereas it must be spinning all the time unless the spinner finishes (I guess it should be intended).
I think this behavior is expected? indicatif doesn't spawn a separate thread unless you explicitly enable that (using enable_steady_tick()
), so unless you do that the spinner will only update whenever you call pb.inc()
.
Yes, this is expected behavior. Perhaps we need a documentation change to make it clear that a '{spinner}' doesn't automatically update unless something is driving it. I'd be happy to submit a PR for that.
@chris-laplante please do!
I documented this in https://github.com/console-rs/indicatif/pull/593 and then forgot to close this issue. Closing now.
Hey there, this is my code:
Everything work as expected but the spinner is not spinning as expected it is intended to be spin indefinitely without stopping until all function returns.
https://github.com/console-rs/indicatif/assets/84739019/103eb01b-5ef7-4431-b1c3-5a1d83d4ab87
My
Cargo.toml
looks like: