From 40d244c44b9f1115359c38280218edb2dcee3abd Mon Sep 17 00:00:00 2001 From: MarcMush Date: Wed, 3 Apr 2024 16:25:06 +0200 Subject: [PATCH 1/2] fix breaking setproperty! --- src/ProgressMeter.jl | 2 ++ test/core.jl | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/ProgressMeter.jl b/src/ProgressMeter.jl index 6cee5f1..7cc9969 100644 --- a/src/ProgressMeter.jl +++ b/src/ProgressMeter.jl @@ -23,6 +23,8 @@ abstract type AbstractProgress end # forward common core properties to main types function Base.setproperty!(p::T, name::Symbol, value) where T<:AbstractProgress if hasfield(T, name) + ty = fieldtype(T, name) + value = value isa ty ? value : convert(ty, value) setfield!(p, name, value) else setproperty!(p.core, name, value) diff --git a/test/core.jl b/test/core.jl index 1b82988..bd05d0e 100644 --- a/test/core.jl +++ b/test/core.jl @@ -71,3 +71,12 @@ wrap = ProgressMeter.ProgressWrapper(A, prog) @test length(wrap) == length(A) @test eltype(wrap) == eltype(A) @test collect(wrap) == collect(A) + +# Test setproperty! on ProgressCore +prog = Progress(10) +prog.desc = "New description" # in ProgressCore +@test prog.desc == "New description" +prog.n = UInt128(20) # in Progress +@test prog.n == 20 +prog.offset = Int8(5) # in ProgressCore +@test prog.offset == 5 From cef2fe1a3126d94b2d6aecc4627908d55e3b813f Mon Sep 17 00:00:00 2001 From: MarcMush Date: Wed, 3 Apr 2024 16:35:36 +0200 Subject: [PATCH 2/2] remove pre-1.3 code --- src/ProgressMeter.jl | 5 ++--- test/test_float.jl | 2 +- test/test_threads.jl | 43 ++++++++++++++++++++----------------------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/ProgressMeter.jl b/src/ProgressMeter.jl index 7cc9969..1ca4ec5 100644 --- a/src/ProgressMeter.jl +++ b/src/ProgressMeter.jl @@ -876,11 +876,10 @@ function showprogress(args...) elseif expr.head == :macrocall macroname = expr.args[1] - if macroname in (Symbol("@distributed"), :(Distributed.@distributed).args[1]) - # can be changed to `:(Distributed.var"@distributed")` if support for pre-1.3 is dropped + if macroname in (Symbol("@distributed"), :(Distributed.var"@distributed")) return showprogressdistributed(args...) - elseif macroname in (Symbol("@threads"), :(Threads.@threads).args[1]) + elseif macroname in (Symbol("@threads"), :(Threads.var"@threads")) return showprogressthreads(args...) end end diff --git a/test/test_float.jl b/test/test_float.jl index 291b3b8..1b2e4ae 100644 --- a/test/test_float.jl +++ b/test/test_float.jl @@ -27,7 +27,7 @@ testfunc2(50, 0.2, 0.2, "progress ", 70) println("Testing floating normal progress bars with changing offset") function testfunc3(n, dt, tsleep, desc, barlen) p1 = Progress(n; dt=dt, desc=desc, barlen=barlen, offset=0) - p2 = Progress(n; dt=dt, desc=desc, barlen=barlen,offset=1) + p2 = Progress(n; dt=dt, desc=desc, barlen=barlen, offset=1) for i = 1:n sleep(tsleep) next!(p1; showvalues = [(:i, i) for _ in 1:i], keep=false) diff --git a/test/test_threads.jl b/test/test_threads.jl index 955c4eb..72a549e 100644 --- a/test/test_threads.jl +++ b/test/test_threads.jl @@ -68,32 +68,29 @@ @test sum(vals) <= thresh @test length(threadsUsed) == threads #Ensure that all threads are used + if (Threads.nthreads() > 1) + threads = Threads.nthreads() - 1 + println("Testing Progress() with Threads.@spawn across $threads threads") + n = 20 #per thread + tasks = Vector{Task}(undef, threads) + # threadsUsed = fill(false, threads) + vals = ones(n*threads) + p = Progress(n*threads) + p.threads_used = 1:threads - @static if VERSION >= v"1.3.0-rc1" #Threads.@spawn not available before 1.3 - if (Threads.nthreads() > 1) - threads = Threads.nthreads() - 1 - println("Testing Progress() with Threads.@spawn across $threads threads") - n = 20 #per thread - tasks = Vector{Task}(undef, threads) - # threadsUsed = fill(false, threads) - vals = ones(n*threads) - p = Progress(n*threads) - p.threads_used = 1:threads - - for t in 1:threads - tasks[t] = Threads.@spawn for i in 1:n - # threadsUsed[Threads.threadid()] = true - vals[(n*(t-1)) + i] = 0 - sleep(0.05 + (rand()*0.1)) - next!(p) - end + for t in 1:threads + tasks[t] = Threads.@spawn for i in 1:n + # threadsUsed[Threads.threadid()] = true + vals[(n*(t-1)) + i] = 0 + sleep(0.05 + (rand()*0.1)) + next!(p) end - wait.(tasks) - @test !any(vals .== 1) #Check that all elements have been iterated - # @test all(threadsUsed) #Ensure that all threads are used (unreliable for @spawn) - else - @info "Threads.nthreads() == 1, so Threads.@spawn tests cannot be meaningfully tested" end + wait.(tasks) + @test !any(vals .== 1) #Check that all elements have been iterated + # @test all(threadsUsed) #Ensure that all threads are used (unreliable for @spawn) + else + @info "Threads.nthreads() == 1, so Threads.@spawn tests cannot be meaningfully tested" end println("Testing @showprogress on a Threads.@threads for loop")