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

jupyter-server: Define a <kernel> record type.

* guix-kernel/jupyter-server.scm (<kernel>): New record type.
(kernel): New procedure.
(run-kernel): Return a <kernel> instead of an alist.
* guix-jupyter-container.scm (register-kernel): Replace 'name' and
'values' parameters with 'kernel'.
(kernel-by-name): Return the kernel itself, not the pair.
(kernel-shell-by-name, kernel-iosub-by-name): Remove.
(proxy-exec-kernel): Adjust accordingly.
parent 40b45870
;;; Guix-kernel -- Guix kernel for Jupyter
;;; Copyright (C) 2018 Evgeny Panfilov <epanfilov@gmail.com>
;;; Copyright (C) 2018 Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr>
;;; Copyright (C) 2018 Ludovic Courtès <ludovic.courtes@inria.fr>
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
......@@ -70,17 +71,13 @@
;; Kernel list.
;;
(define (register-kernel vhash name values)
(vhash-cons name values vhash))
(define (register-kernel vhash kernel)
(vhash-cons (kernel-name kernel) kernel vhash))
(define (kernel-by-name vhash name)
(vhash-assoc name vhash))
(define (kernel-shell-by-name vhash name)
(assoc-ref (vhash-assoc name vhash) "shell"))
(define (kernel-iosub-by-name vhash name)
(assoc-ref (vhash-assoc name vhash) "iosub"))
(match (vhash-assoc name vhash)
((_ . kernel) kernel)
(#f #f)))
;;
;; Execution.
......@@ -126,9 +123,8 @@
error-or-result streams)))))
(let* ((kernel (kernel-by-name kernels name))
(shell (kernel-shell-by-name kernels name))
(iosub (kernel-iosub-by-name kernels name))
(shell (kernel-shell kernel))
(iosub (kernel-iosub kernel))
(uuid (cadr parts)))
(zmq-send-msg-parts shell (cddr parts))
......@@ -315,7 +311,7 @@
(values kernels
(proxy-exec-kernel kernels name parts count))
(let* ((new-kernel (run-kernel context name uuid notebook-key))
(new-kernels (register-kernel kernels name new-kernel)))
(new-kernels (register-kernel kernels new-kernel)))
(values new-kernels
(proxy-exec-kernel new-kernels name parts count))))))
((magic-html? code)
......
......@@ -26,14 +26,41 @@
#:use-module (json)
#:use-module (rnrs bytevectors)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-26)
#:export (find-kernel-by-name
run-kernel))
run-kernel
kernel
kernel?
kernel-name
kernel-pid
kernel-control
kernel-shell
kernel-standard-input
kernel-heartbeat
kernel-iosub))
;;
;; Kernel execution.
;;
;; Type of a proxied Jupyter kernel.
(define-record-type <kernel>
(%kernel name pid control shell stdin heartbeat iosub)
kernel?
(name kernel-name) ;string
(pid kernel-pid) ;integer
(control kernel-control) ;zmq socket
(shell kernel-shell) ;zmq socket
(stdin kernel-standard-input) ;zmq socket
(heartbeat kernel-heartbeat) ;zmq socket
(iosub kernel-iosub)) ;zmq socket
(define* (kernel name pid #:key control shell
standard-input heartbeat iosub)
(%kernel name pid control shell standard-input heartbeat iosub))
(define (jupyter-kernel-path)
"Return the default search path for Jupyter kernels."
;; Note: In container environments, 'JUPYTER_PATH' is typically unset
......@@ -165,12 +192,12 @@ return its PID."
(string-append addr
(number->string port))))
(kernel `(("pid" . ,pid)
("control" . ,socket-control)
("shell" . ,socket-shell)
("stdin" . ,socket-stdin)
("heartbeat" . ,socket-heartbeat)
("iosub" . ,socket-iosub))))
(kernel (kernel name pid
#:control socket-control
#:shell socket-shell
#:standard-input socket-stdin
#:heartbeat socket-heartbeat
#:iosub socket-iosub)))
(zmq-set-socket-option socket-iosub ZMQ_SUBSCRIBE "")
(zmq-set-socket-option socket-shell ZMQ_IDENTITY (utf8->string uuid))
......
Supports Markdown
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