Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print progressbar also for n=1 and n=2 #261

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/Manifest.toml
.vscode
8 changes: 6 additions & 2 deletions src/ProgressMeter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ function updateProgress!(p::Progress; showvalues = (), truncate_lines = false, v
p.desc = desc
end
p.offset = offset

if p.counter >= p.n
if p.counter == p.n && p.printed
if p.counter == p.n #&& p.printed
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timholy I'm not sure about the effect of this. What's the purpose of p.printed?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's part of ensuring you don't start printing only at finish: you have to print at least one update for this block to print anything at all.

t = time()
barlen = p.barlen isa Nothing ? tty_width(p.desc, p.output, p.showspeed) : p.barlen
percentage_complete = 100.0 * p.counter / p.n
Expand All @@ -292,6 +293,7 @@ function updateProgress!(p::Progress; showvalues = (), truncate_lines = false, v
end
return nothing
end

if ignore_predictor || predicted_updates_per_dt_have_passed(p)
t = time()
if p.counter > 2
Expand Down Expand Up @@ -460,7 +462,9 @@ function updateProgress!(p::ProgressUnknown; showvalues = (), truncate_lines = f
end
end

predicted_updates_per_dt_have_passed(p::AbstractProgress) = p.counter - p.prev_update_count >= p.check_iterations
predicted_updates_per_dt_have_passed(p::AbstractProgress) =
p.counter <= 2 || # otherwise the first 2 are never printed, independently of dt
p.counter - p.prev_update_count >= p.check_iterations

function is_threading(p::AbstractProgress)
Threads.nthreads() == 1 && return false
Expand Down
5 changes: 5 additions & 0 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ end
println("Testing original interface...")
testfunc(107, 0.01, 0.01)

println("Testing n=1") # Issue #258
testfunc(1, 0.1, 1)

println("Testing n=2") # Issue #258
testfunc(1, 0.1, 1)

function testfunc2(n, dt, tsleep, desc, barlen)
p = ProgressMeter.Progress(n, dt, desc, barlen)
Expand Down