timholy / ProgressMeter.jl

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

Different order of message when redirecting to log file #230

Open szcf-weiya opened 2 years ago

szcf-weiya commented 2 years ago

Suppose I have the following simple script

# file test.jl
using ProgressMeter

for j = 1:3
    println("j = $j")
    @showprogress for i = 1:10
        sleep(1)
    end
end

then I run it from the command line. The progress bar and the println message displayed in the expected order

$ julia test.jl
j = 1
Progress: 100%|█████████████████████████████████████████████████████████| Time: 0:00:10
j = 2
Progress: 100%|█████████████████████████████████████████████████████████| Time: 0:00:10
j = 3
Progress: 100%|█████████████████████████████████████████████████████████| Time: 0:00:10

But if I redirect it to a log file,

$ julia test.jl &> test.log

the log file would postpone the println message when I checked it with tail -f test.log, and they are printed only after the progress bar has been finished. The resulting log file is

Progress: 100%|█████████████████████████████████████████| Time: 0:00:10
Progress: 100%|█████████████████████████████████████████| Time: 0:00:10
Progress: 100%|█████████████████████████████████████████| Time: 0:00:10
j = 1
j = 2
j = 3

I am wondering whether it is possible to write the message into files in order. I am not sure if this is related to the package itself, or the mechanism of redirection, so just try to ask here.