Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

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

Don't spawn a default environment upfront.

This ensures we reply to "kernel_info_request" in a timely fashion, and
that we don't spawn a useless environment.  It also allows the user to
not repeat ";;guix run my-env" in subsequent cells since the default
environment is now recorded across cells.

* guix-jupyter-kernel.scm (%default-environment-property): New variable.
(proxy-state-default-environment, set-proxy-state-default-environment):
New procedures.
(create-environment): Call 'set-proxy-state-default-environment'.
(reply-execute-request): Use the environment returned by
'proxy-state-default-environment'.  Print an error as HTML when it's
<top level>: Remove call to 'start-container' for the "default"
parent def14612
......@@ -64,6 +64,19 @@
"Return the <store-connection> associated with STATE."
(proxy-state-property state %store-property))
(define %default-environment-property
;; Key used to access the name of the default environment.
(list 'environment 'property))
(define (proxy-state-default-environment state)
"Return the name of the default execution environment or #f."
(proxy-state-property state %default-environment-property))
(define (set-proxy-state-default-environment state name)
"Use NAME as the default environment."
(set-proxy-state-property state %default-environment-property
;; HTML.
......@@ -149,7 +162,8 @@ to KERNEL as a reply to MESSAGE, and return STATE suitably adjusted."
(state (register-proxied name container state)))
(monitor-client container)
(send-message container message)
(increment-execution-count state)))
(set-proxy-state-default-environment (increment-execution-count state)
(define (reply-execute-request kernel kind message state)
(let* ((content (message-content message))
......@@ -196,13 +210,29 @@ to KERNEL as a reply to MESSAGE, and return STATE suitably adjusted."
((magic-html? code)
(reply-html kernel message (delete-magic code) count)
(increment-execution-count state))
((proxy-state-default-environment state)
(lambda (environment)
(let ((proxied (lookup-proxied environment state)))
(format/log "evaluating code in environment ~s (PID ~s)~%"
environment (kernel-pid proxied))
(send-message proxied message
#:kernel-socket kind)
(increment-execution-count state))))
(let ((proxied (lookup-proxied "default" state)))
(format/log "evaluating code in default container (PID ~s)~%"
(kernel-pid proxied))
(send-message proxied message
#:kernel-socket kind)
(increment-execution-count state)))))
(reply-html kernel message
`(div "You have not selected an execution environment
yet. You can create one by entering a “magic command” in a cell as follows:"
(p (code ";;guix environment my-environment <- \
python-ipython python-ipykernel"))
"You can then select a kernel and hand it code
to execute:"
(p (code
(pre ";;guix kernel my-environment ipython\n"
"2 + 2")))))
(λ error
(reply-html kernel message (error->html error) count)
(increment-execution-count state)))))
......@@ -337,14 +367,8 @@ that container."
(sigaction SIGTERM (exit-handler kernel))
(sigaction SIGINT (exit-handler kernel))
(let* ((sub-kernel (with-store store ;FIXME: not nice
(run-with-store store
(start-container container-context "default"
(manifest '())))))
(state (register-proxied "default" sub-kernel
(proxy-state kernel))))
(with-store store
(serve-kernels (list kernel sub-kernel)
(proxy-request-handler dispatch-route)
(set-proxy-state-property state
%store-property store)))))
(with-store store
(serve-kernels (list kernel)
(proxy-request-handler dispatch-route)
(set-proxy-state-property (proxy-state kernel)
%store-property store))))
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