# How to attach to an existing remote REPL?

**URL:** <https://discourse.julialang.org/t/how-to-attach-to-an-existing-remote-repl/27608>\
**Category:** Performance\
**Tags:** distributed\
**Created:** [August 16, 2019, 9:46am UTC](https://discourse.julialang.org/t/how-to-attach-to-an-existing-remote-repl/27608 "2019-08-16T09:46:22Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [August 30, 2019, 8:44am UTC](https://discourse.julialang.org/t/how-to-attach-to-an-existing-remote-repl/27608/21 "2019-08-30T08:44:45Z")

</div>

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](https://jupyter-client.readthedocs.io/en/stable/kernels.html#kernel-specs)

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [August 30, 2019, 9:23am UTC](https://discourse.julialang.org/t/how-to-attach-to-an-existing-remote-repl/27608/22 "2019-08-30T09:23:49Z")

</div>

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` ☹ 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`.

---

<div class="post-metadata">

**Author:** ![nico202](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nico202/32/1009_2.png) [@nico202](https://discourse.julialang.org/u/nico202)\
**Post date:** [October 6, 2019, 11:00am UTC](https://discourse.julialang.org/t/how-to-attach-to-an-existing-remote-repl/27608/23 "2019-10-06T11:00:48Z")

</div>

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

```julia
## 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

```

---

<div class="post-metadata">

**Author:** ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)\
**Post date:** [March 22, 2021, 5:01am UTC](https://discourse.julialang.org/t/how-to-attach-to-an-existing-remote-repl/27608/24 "2021-03-22T05:01:07Z")

</div>

I just registered a package for this - [GitHub - c42f/RemoteREPL.jl: Connect a REPL to a remote Julia process](https://github.com/c42f/RemoteREPL.jl)

[Previous page](https://discourse.julialang.org/t/how-to-attach-to-an-existing-remote-repl/27608.md?page=1)
