timholy / ProgressMeter.jl

Progress meter for long-running computations
MIT License
694 stars 91 forks source link

`@async` blocks #248

Closed rikhuijzer closed 8 months ago

rikhuijzer commented 2 years ago

Is the following behaviour expected? The Time should be 10 seconds, that is, the meter should run concurrently during the "long" running fib computation. However, it always takes more than 10 seconds to finish:


julia> using ProgressMeter

julia> function show_progress()
           p = ProgressMeter.ProgressUnknown()
           for i in 1:10
               ProgressMeter.update!(p)
               sleep(1)
           end
           ProgressMeter.finish!(p)
       end;

julia> fib(n) = n <= 1 ? n : fib(n - 1) + fib(n - 2);

julia> @time fib(44);
  4.591181 seconds

julia> show_progress()
Progress:  0     Time: 0:00:10

julia> @async(fib(44)); show_progress();
Progress:  0     Time: 0:00:13

julia> @async(show_progress()); fib(44); # This one blocks for a few seconds before it starts.

Progress:  0     Time: 0:00:10
MarcMush commented 8 months ago

I don't think that's a problem with ProgressMeter, I see the same behavior with println(i)

function show_progress()
    for i in 1:10
        println(i)
        sleep(1)
    end
end