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

messages: Add <kernel-status>.

* jupyter/messages.scm (<kernel-status>): New record type.
* jupyter/kernels.scm (pub): Expect a <kernel-status> record and use
'kernel-status->json'.
(pub-busy, pub-idle): Pass a <kernel-status> record.
* tests/kernels.scm ("run-kernel python3")
("kernel_info_request", "execute_request"): Use 'json->kernel-status'
instead of alists.
parent f8d0fcbb
......@@ -439,16 +439,18 @@ identity (bytevector)."
#:recipient recipient)))
(define (pub kernel message status)
(let ((content `(("execution_state" . ,status))))
(let ((content (kernel-status->json status)))
(send-message kernel (reply message "status"
(scm->json-string content))
#:kernel-socket kernel-iopub)))
(define (pub-busy kernel message)
(pub kernel message "busy"))
(pub kernel message
(kernel-status (execution-state 'busy))))
(define (pub-idle kernel message)
(pub kernel message "idle"))
(pub kernel message
(kernel-status (execution-state 'idle))))
;;
;; Reply.
......
......@@ -72,7 +72,13 @@
language-info-mime-type
language-info-file-extension
language-info-pygments-lexer
language-info-codemirror-mode))
language-info-codemirror-mode
kernel-status?
kernel-status
kernel-status-execution-state
json->kernel-status
kernel-status->json))
;;; Commentary:
;;;
......@@ -295,3 +301,11 @@ This is a low-level procedure for internal use."
(help-links kernel-info-reply-help-links
(json "help_links")
(default '())))
(define-json-mapping <kernel-status> kernel-status
make-kernel-status
kernel-status?
json->kernel-status <=> kernel-status->json
(execution-state kernel-status-execution-state
(json "execution_state" string->symbol symbol->string)
(default 'idle)))
......@@ -52,9 +52,9 @@
(let ((greetings (read-message %kernel 5000)))
(or (not greetings)
(list (message-type greetings)
(assoc-ref (json-string->scm
(message-content greetings))
"execution_state"))))))))
(kernel-status-execution-state
(json->kernel-status
(message-content greetings))))))))))
(unless %kernel (test-skip 1))
(test-equal "kernel_info_request"
......@@ -75,14 +75,12 @@
(match (filter (type-predicate "status") replies)
((busy idle)
;; We got two message: busy *then* idle.
(and (string=? "busy"
(assoc-ref (json-string->scm
(message-content busy))
"execution_state"))
(string=? "idle"
(assoc-ref (json-string->scm
(message-content idle))
"execution_state"))
(and (eq? 'busy
(kernel-status-execution-state
(json->kernel-status (message-content busy))))
(eq? 'idle
(kernel-status-execution-state
(json->kernel-status (message-content idle))))
(equal? (message-parent-header busy)
(message-header request))
(equal? (message-parent-header idle)
......@@ -128,14 +126,12 @@
(match (filter (type-predicate "status") replies)
((busy idle)
;; We got two message: busy *then* idle.
(and (string=? "busy"
(assoc-ref (json-string->scm
(message-content busy))
"execution_state"))
(string=? "idle"
(assoc-ref (json-string->scm
(message-content idle))
"execution_state"))
(and (eq? 'busy
(kernel-status-execution-state
(json->kernel-status (message-content busy))))
(eq? 'idle
(kernel-status-execution-state
(json->kernel-status (message-content idle))))
(equal? (message-parent-header busy)
(message-header request))
(equal? (message-parent-header idle)
......
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