Stream: helpdesk (published)

Topic: ✔ Rocket.jl: Has anyone used it with ProgressLogging.jl?


view this post on Zulip G Gundam (Dec 19 2024 at 02:52):

Let's start with something simple.

julia> using Rocket

julia> ints = iterable(1:10)
IterableObservable(Int64, UnitRange{Int64}, AsapScheduler)

julia> subscribe!(ints, logger("n"))
[n] Data: 1
[n] Data: 2
[n] Data: 3
[n] Data: 4
[n] Data: 5
[n] Data: 6
[n] Data: 7
[n] Data: 8
[n] Data: 9
[n] Data: 10
[n] Completed
VoidTeardown()

ProgressLogging.jl

How could I hook the animated progress bar from ProgressLogging.jl into this iteration? (The logger(n) is just there for demo purposes. Feel free to get rid of it if you want.)

view this post on Zulip G Gundam (Dec 19 2024 at 02:55):

PS: I think you have to setup TerminalLoggers.jl to get nice animations in the REPL. Do something like this first.

using TerminalLoggers
global_logger(TerminalLogger(right_justify=80))
using ProgressLogging

view this post on Zulip G Gundam (Dec 19 2024 at 03:52):

Blocking take! was the key.

function start_iteration(observable)
    # Let a LambdaActor subscribe to candle_subject for progress logging.
    i = 1
    len = length(observable.iterator)
    ch = Channel(1)

    ProgressLogging.progress() do id
        # setup progress
        on_next = function(n::Int)
            println("i:$(i) len:$(len) ratio=$(i/len)")
            @info "running" _id=id progress=(i/len)
            i += 1
            sleep(0.1)
        end
        on_complete() = put!(ch, 1)
        subscribe!(observable, lambda(;on_next, on_complete))

        # block until our on_complete fires
        take!(ch)
    end
end

It's used like this:

julia> start_iteration(ints)

view this post on Zulip Notification Bot (Dec 19 2024 at 03:55):

G Gundam has marked this topic as resolved.


Last updated: Dec 28 2024 at 04:38 UTC