Add jupyter-restart-kernel

This commit is contained in:
Nathaniel Nicandro 2020-12-13 16:18:20 -06:00
parent 5857352135
commit f92e14f62b
3 changed files with 20 additions and 2 deletions

View file

@ -473,6 +473,14 @@ longer connected to a kernel."
(jupyter-publish 'shutdown))
(jupyter-disconnect client))))
(cl-defmethod jupyter-restart-kernel ((client jupyter-kernel-client))
"Restart the kernel CLIENT is connected to."
(when (jupyter-connected-p client)
(pcase-let ((`(,_ ,kaction-sub) (oref client io)))
(jupyter-run-with-io kaction-sub
(jupyter-publish 'restart))
(jupyter-disconnect client))))
(cl-defmethod jupyter-interrupt-kernel ((client jupyter-kernel-client))
"Interrupt the kernel CLIENT is connected to."
(when (jupyter-connected-p client)

View file

@ -125,8 +125,11 @@ nil."
"Notify that the kernel launched."
(message "%s kernel shutdown...done" (jupyter-kernel-name kernel)))
(defun jupyter-restart (kernel)
"Shutdown then re-launch KERNEL."
(cl-defgeneric jupyter-restart ((kernel jupyter-kernel))
"Restart KERNEL.
The default implementation shuts down and then re-launches
KERNEL."
(jupyter-shutdown kernel)
(jupyter-launch kernel))

View file

@ -282,6 +282,8 @@ this case FN will be evaluated on KERNEL."
(jupyter-shutdown kernel)
(websocket-close ws)
(setq shutdown t))
('restart
(jupyter-restart kernel))
(`(action ,fn)
(funcall fn kernel))))))))
@ -333,6 +335,11 @@ using its SPEC."
(when session
(jupyter-api-shutdown-kernel server id))))
(cl-defmethod jupyter-restart ((kernel jupyter-server-kernel))
(pcase-let (((cl-struct jupyter-server-kernel server id session) kernel))
(when session
(jupyter-api-restart-kernel server id))))
(cl-defmethod jupyter-interrupt ((kernel jupyter-server-kernel))
(pcase-let (((cl-struct jupyter-server-kernel server id) kernel))
(jupyter-api-interrupt-kernel server id)))