-
Notifications
You must be signed in to change notification settings - Fork 11
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
Module update #45
Module update #45
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks! I'm definitely happy to make changes to support this use case :)
I think the "right way" to do this is to use the on_client_connect
hook in serve_repl
to grab a handle to the ServerSideSession
each time a client connects. Then given the session
you can just set session.in_module
whenever Pluto creates a new module (does Pluto provide a hook so you know when this happens?) That way you don't need any globals.
The only tricky thing is that there's no on_client_disconnect
hook in RemoteREPL so the pluto-side hooks won't know when to be detached from the session, even after the session is disconnected.
So I wonder what to do about that. We could add an on_client_disconnect
hook, but that seems a bit awkward if the user wants to associate their own data structures with the session.
Maybe we should add a field to ServerSideSession
... like custom_session::Any
or something, which can be set by on_client_connect
and just call close()
on it as part of close(::ServerSideSession)
.
That seems a bit wonky too, but I think it's approximately the right kind of thing - I think what we want here is some notion of "custom server side session".
I guess to do this we need to wrap all the mutable struct MySession
@atomic name::String
end
function setsessionname!(ses::MySession, newname)
@atomic ses.name = newname
end
function dummy_serve(on_client_connect=nothing)
Channel{MySession}(1) do ch
mysession = MySession("Main")
if !isnothing(on_client_connect)
on_client_connect(mysession)
put!(ch, mysession)
end
i = 0
while i < 5
sleep(2.0)
@info "evaluating commands in $(mysession.name)"
i += 1
end
end
end and then the server (Pluto) will call it like: julia> ses = take!(dummy_serve(x -> setsessionname!(x, "module#1")));
[ Info: evaluating commands in module#1
[ Info: evaluating commands in module#1
[ Info: evaluating commands in module#1
julia> setsessionname!(ses, "module#2");
[ Info: evaluating commands in module#2
[ Info: evaluating commands in module#2
But then what happens in Also what about mutexing ? If we would return a
Now that I think about it, the |
This is one way to provide the sessions back to the caller. But I don't particularly love firing off that independent I'd probably be inclined to have the user pass the channel instead. (Ugh, if only Julia had Go's
Yep this is a good point I think. "Unlikely" to cause a real problem, but data races are evil :-D Actually a nicely appropriate way to fix this would be to communicate with I think this is the right way forward, it's just a little tricky because right now the code assumes that But if all that's too big of a rearrangement to contemplate, using an
This kind of polling generally leads to awkward code because it tends to look like while true
if !isopen(session.socket)
break
end
do_something(session.socket) # Is session.socket open here?
end The awkwardness here is that |
Good question. Possibly it would be a place to stash any other session <--> pluto mappings you need? But maybe that's not necessary and introduces extra coupling that we don't really need. If the user can get hold of the In that case, they can wrap whatever logic they like around |
Hey! It's been a while :) Could you remind me of the use case? Is this work for a RemoteREPL server in the Pluto notebook, and a client in a Julia REPL? So in your notebook you define |
hey hey. yes. Basically you should be able to access all the namespace of the newest notebook module. The Pluto notebook looks like this https://gist.github.com/filchristou/80ab232ca1be67fb59de689913f41785 No changes are needed on the Pluto side. |
Hello. Thanks for the awesome package :)
I 've been playing around to get RemoteREPL.jl to work well with Pluto.
The problem with Pluto is that everytime there is a change/evaluation in the notebook it creates a new Module.
So the client must explicitly change the module where the commands should be evaluated and that's tedious.
I tried to think of a non-intrusive way to solve this, but I couldn't wrap my head around it.
Instead here is an example of how RemoteREPL.jl could be modified.
Right now I have a global
const Channel
that the server can asynchronously modify with theputmodule!
command.Pluto side
You can see a Pluto notebook on gist
Basically it steps on the PlutoLinks.jl / PlutoHooks.jl to schedule an update of the module of RemoteREPL (with
putmodule!
) every second.(I think this could be more clever but it's just a minimal working example)
Test
Run Pluto notebook and from the REPL do:
The RemoteREPL now will always be on the last update of the Pluto notebook.
This is just a draft.
I myself am not very happy with the restriction to have only one global Channel,
but before I move on I would like to know what do you think.
So basically two questions: