Commit 22e7d33f authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

kernels: 'run-kernel' no longer requires a UUID parameter.

* jupyter/kernels.scm (run-kernel): Remove 'uuid' parameter and add
 #:identity parameter.  Do not set ZMQ_IDENTITY on SOCKET-SHELL when
 #:identity is #f.
* guix-jupyter-container.scm (reply-execute-request): Pass #:identity to
'run-kernel'.
* tests/kernels.scm (%kernel-uuid): Remove.
("run-kernel python3"): Remove %KERNEL-UUID argument from 'run-kernel'
call.
("execute_request"): Remove #:recipient argument to 'send-message'.
Remove reference to %KERNEL-UUID.
parent 22b789fc
;;; Guix-kernel -- Guix kernel for Jupyter ;;; Guix-kernel -- Guix kernel for Jupyter
;;; Copyright (C) 2018 Evgeny Panfilov <epanfilov@gmail.com> ;;; Copyright (C) 2018 Evgeny Panfilov <epanfilov@gmail.com>
;;; Copyright (C) 2018 Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr> ;;; Copyright (C) 2018 Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr>
;;; Copyright (C) 2018 Ludovic Courtès <ludovic.courtes@inria.fr> ;;; Copyright (C) 2018, 2019 Ludovic Courtès <ludovic.courtes@inria.fr>
;;; ;;;
;;; This program is free software: you can redistribute it and/or modify ;;; 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 ;;; it under the terms of the GNU General Public License as published by
...@@ -239,8 +239,9 @@ KEY for signing." ...@@ -239,8 +239,9 @@ KEY for signing."
(string->utf8 name) message) (string->utf8 name) message)
(values kernels (+ count 1))) (values kernels (+ count 1)))
(let* ((new-kernel (run-kernel context name (let* ((new-kernel (run-kernel context name
(string->utf8 name) notebook-key
notebook-key)) #:identity
(string->utf8 name)))
(kernel (socket->kernel socket notebook-key)) (kernel (socket->kernel socket notebook-key))
(new-kernels (register-kernel kernels new-kernel))) (new-kernels (register-kernel kernels new-kernel)))
(relay-message (kernel-shell new-kernel) kernel (relay-message (kernel-shell new-kernel) kernel
......
...@@ -200,7 +200,7 @@ return its PID." ...@@ -200,7 +200,7 @@ return its PID."
(apply execl command arguments))) (apply execl command arguments)))
pid))) pid)))
(define (run-kernel context name uuid key) (define* (run-kernel context name key #:key identity)
(let* ((socket-control (zmq-create-socket context ZMQ_DEALER)) (let* ((socket-control (zmq-create-socket context ZMQ_DEALER))
(socket-shell (zmq-create-socket context ZMQ_DEALER)) (socket-shell (zmq-create-socket context ZMQ_DEALER))
(socket-stdin (zmq-create-socket context ZMQ_DEALER)) (socket-stdin (zmq-create-socket context ZMQ_DEALER))
...@@ -235,9 +235,15 @@ return its PID." ...@@ -235,9 +235,15 @@ return its PID."
#:standard-input socket-stdin #:standard-input socket-stdin
#:heartbeat socket-heartbeat #:heartbeat socket-heartbeat
#:iosub socket-iosub))) #:iosub socket-iosub)))
(zmq-set-socket-option socket-iosub ZMQ_SUBSCRIBE "") (zmq-set-socket-option socket-iosub ZMQ_SUBSCRIBE "")
(zmq-set-socket-option socket-shell ZMQ_IDENTITY (utf8->string uuid))
;; <http://zguide.zeromq.org/page:all#The-Extended-Reply-Envelope> says
;; that ZeroMQ "generate[s] a 5 byte identity by default", so usually we
;; don't need to provide our own identity.
(when identity
(zmq-set-socket-option socket-shell ZMQ_IDENTITY
(utf8->string identity)))
;; Sub socket connection. ;; Sub socket connection.
(zmq-connect socket-control (addr-p port-control)) (zmq-connect socket-control (addr-p port-control))
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
(define %context (define %context
(zmq-create-context)) (zmq-create-context))
(define %kernel-uuid #vu8(1 2 3 4 5 6 7 8 9 0))
(define %kernel-key "secretkey") (define %kernel-key "secretkey")
(define %kernel #f) (define %kernel #f)
...@@ -36,7 +35,7 @@ ...@@ -36,7 +35,7 @@
(unless (find-kernel-by-name "python3") (test-skip 1)) (unless (find-kernel-by-name "python3") (test-skip 1))
(test-assert "run-kernel python3" (test-assert "run-kernel python3"
(let ((kernel (run-kernel %context "python3" %kernel-uuid %kernel-key))) (let ((kernel (run-kernel %context "python3" %kernel-key)))
(set! %kernel kernel) (set! %kernel kernel)
(and (kernel? (pk 'kernel kernel)) (and (kernel? (pk 'kernel kernel))
(kill (kernel-pid kernel) 0)))) (kill (kernel-pid kernel) 0))))
...@@ -47,11 +46,9 @@ ...@@ -47,11 +46,9 @@
(scm->json-string (scm->json-string
'((code . "40 + 2\n") '((code . "40 + 2\n")
(silent . #f)))))) (silent . #f))))))
(send-message %kernel request (send-message %kernel request)
#:recipient %kernel-uuid)
(let ((reply (pk 'reply (read-message %kernel)))) (let ((reply (pk 'reply (read-message %kernel))))
(and (message? reply) (and (message? reply)
(bytevector=? (message-sender reply) %kernel-uuid)
(equal? (message-parent-header reply) (equal? (message-parent-header reply)
(message-header request)) (message-header request))
(string=? (message-type reply) "execute_reply") (string=? (message-type reply) "execute_reply")
......
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