Commit f115d70a authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

Terminate and unregister existing proxy when recreating an environment.

* guix/jupyter/proxy.scm (unregister-proxied, terminate-proxied-kernel):
New procedures.
* guix-jupyter-kernel.scm (reply-execute-request): When 'lookup-proxied'
returns true, call 'unmonitor-client' and 'terminate-proxied-kernel',
and then 'create-environment'.
parent 5945ac36
......@@ -169,8 +169,14 @@ to KERNEL as a reply to MESSAGE, and return STATE suitably adjusted."
#:kernel kernel
#:message message))
((? kernel? proxy)
(send-message kernel message)
(increment-execution-count state))))
(format/log "terminating existing '~a' environment~%"
name)
(unmonitor-client proxy)
(terminate-proxied-kernel proxy)
(create-environment name specs
(unregister-proxied name state)
#:kernel kernel
#:message message))))
((lst ...)
(reply-html kernel message
(sxml->html-string
......
......@@ -18,6 +18,8 @@
#:use-module (guix jupyter logging)
#:use-module (jupyter messages)
#:use-module (jupyter kernels)
#:use-module (jupyter servers)
#:use-module (json)
#:use-module (gcrypt base16)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9 gnu)
......@@ -32,13 +34,17 @@
set-proxy-state-client-id
register-proxied
unregister-proxied
lookup-proxied
proxy-state-proxied-number
increment-execution-count
set-proxy-state-execution-count
proxy-state-property
set-proxy-state-property
terminate-proxied-kernel
terminate-proxied-kernels
proxy-request-handler))
......@@ -71,6 +77,12 @@
(proxy-state-proxied state))))
(set-proxy-state-proxied state table)))
(define (unregister-proxied name state)
"Unregister the kernel associated with the given NAME, a string, from
STATE's list of proxied kernels."
(let ((table (vhash-delete name (proxy-state-proxied state))))
(set-proxy-state-proxied state table)))
(define (lookup-proxied name state)
"Return the proxied kernel NAME from STATE, or #f if it could not be
found."
......@@ -87,6 +99,23 @@ found."
(let ((count (proxy-state-execution-count state)))
(set-proxy-state-execution-count state (+ 1 count))))
(define (terminate-proxied-kernel kernel)
"Send KERNEL a \"shutdown_request\" and terminate its process."
(define shutdown
(message (header "shutdown_request" "user" "1234") ;FIXME
(scm->json-string '((restart . #f)))))
(format/log "terminating proxy with PID ~s...~%"
(kernel-pid kernel))
(send-message kernel shutdown
#:kernel-socket kernel-control)
(close-kernel kernel)
(usleep 500000)
(catch 'system-error
(lambda ()
(kill (kernel-pid kernel) SIGTERM))
(const #t)))
(define (terminate-proxied-kernels message state)
"Terminate all the proxies listed in the CONTAINERS vhash, sending them
MESSAGE. Return the new state."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment