How to attach to an existing remote REPL?

Actually, creating a kernel.json with -L myapp.jl julia options may be the simplest and cleanest solution: Making kernels for Jupyter — jupyter_client 7.3.5 documentation

Going down this path, even simpler would be to have supervisord starting a tmux session which starts the Julia app. Then one can simply attatch to the tmux session.

I just tried it and I can start a new byobu session to start a Genie app with:
byobu new-session -s "session_name" "bin/server"

This can be passed to supervisord


Update 1

Unfortunately, not so easy… By default supervisord would supervise tmux :frowning: I think it can be set up so that the Julia app creates a pidfile and supervisor watches that. Will investigate, but it takes more digging…


Update 2

After more digging it’s a total no go. Looks like tmux can’t be started through supervisor.

1 Like

What about something like the following? Adding an authentication to this is easy

## Run this on the server
using Sockets
@async begin
    server = listen(2000)
    while true
        sock = accept(server)
        @async while isopen(sock)
            @info "Receiving content"
            content = String(readavailable(sock))
            @info "Running: $content"
            try
                redirect_stdout(sock) do
                    redirect_stderr(sock) do
                        res = eval(Meta.parse(content))
                        res !== nothing && println(sock, res)
                    end
                end
            catch e
                @warn e
            end
        end
    end
end


## Client
using Sockets
serv = connect(2000)
@async while isopen(serv)
    println(stdout, readline(serv))
end
macro |(content)
    c = string(content)
    return :(println(serv, $c); flush(serv))
end
@| begin variable = 10
    end

@| variable
# prints 10
1 Like

I just registered a package for this - GitHub - c42f/RemoteREPL.jl: Connect a REPL to a remote Julia process

6 Likes