ProgressMeter.jl icon indicating copy to clipboard operation
ProgressMeter.jl copied to clipboard

asyncmap

Open bjarthur opened this issue 7 years ago • 3 comments

progressmeter.jl is awesome! works great for map, but sadly not asyncmap:

julia> using ProgressMeter
julia> prog = Progress(100)
julia> map(x->(sleep(1); next!(prog)),1:100)      ### works!
Progress:   3%|█                                        |  ETA: 0:02:43

julia> asyncmap(x->(sleep(1); next!(prog)),1:100; ntasks=1)    ### works!
Progress:   5%|██                                       |  ETA: 0:02:58

julia> asyncmap(x->(sleep(1); next!(prog)),1:100; ntasks=3)    ### no worky :(
Progress:   7%|███                                      |  ETA: 0:03:36Progress:   8%|███                                      |  ETA: 0:03:07Progress:   9%|████                                     | Progress:  10%|████                                     |  ETA: 0:02:36Progress:  11%|█████                                    |  ETA: 0:02:20Progress:  12%|█████                                    | Progress:  13%|█████                                    |  ETA: 0:02:02Progress:  14%|██████                                   |  ETA: 0:01:52Progress:  15%|██████

any idea why it would print multiple progress bars for the asyncmap with multiple tasks, but not for that with a single task, or with map? thanks.

bjarthur avatar Apr 16 '18 18:04 bjarthur

If the tasks are executing asynchronously, there is nothing to keep one task from starting to print while another is in the middle of printing.

See #109 for a possible solution.

zsunberg avatar Aug 16 '18 20:08 zsunberg

A workaround without RemoteChannel:

prog = Progress(100)
ch = Channel{Nothing}(Inf)
task = @async begin
    for _ in ch
        next!(prog)
    end
    finished!(prog)
end
asyncmap(x->(sleep(0.2); put!(ch, nothing)),1:100; ntasks=3)
close(ch)

yiyuezhuo avatar Jul 07 '21 07:07 yiyuezhuo

@yiyuezhuo , this seems to be working. However, do you have any idea why it takes a bit of time (hangs) after the progress bar has reached 100% to close the channel?

gitboy16 avatar Nov 17 '21 11:11 gitboy16

fixed by #322 with safe_lock=true (default is false if nthreads()=1)

MarcMush avatar Jul 13 '24 09:07 MarcMush