mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-06 07:51:39 -05:00
Refactor jupyter-start-new-kernel
to use jupyter-missing-request
This commit is contained in:
parent
7e36ea1101
commit
6178a53638
1 changed files with 18 additions and 10 deletions
|
@ -243,7 +243,6 @@ If RESTART is non-nil, request a restart instead of a complete shutdown."
|
||||||
(jupyter-send manager "interrupt_request" msg))
|
(jupyter-send manager "interrupt_request" msg))
|
||||||
(interrupt-process (oref manager kernel) t)))
|
(interrupt-process (oref manager kernel) t)))
|
||||||
|
|
||||||
;; TODO: kernel existence
|
|
||||||
(defun jupyter-start-new-kernel (kernel-name &optional client-class)
|
(defun jupyter-start-new-kernel (kernel-name &optional client-class)
|
||||||
(setq client-class (or client-class 'jupyter-kernel-client))
|
(setq client-class (or client-class 'jupyter-kernel-client))
|
||||||
(unless (child-of-class-p client-class 'jupyter-kernel-client)
|
(unless (child-of-class-p client-class 'jupyter-kernel-client)
|
||||||
|
@ -251,17 +250,26 @@ If RESTART is non-nil, request a restart instead of a complete shutdown."
|
||||||
(list '(subclass jupyter-kernel-client) client-class)))
|
(list '(subclass jupyter-kernel-client) client-class)))
|
||||||
(let (km kc)
|
(let (km kc)
|
||||||
(setq km (jupyter-kernel-manager :name kernel-name))
|
(setq km (jupyter-kernel-manager :name kernel-name))
|
||||||
(jupyter-start-kernel km)
|
|
||||||
(setq kc (jupyter-make-client km client-class))
|
(setq kc (jupyter-make-client km client-class))
|
||||||
(jupyter-start-channels kc)
|
(jupyter-start-channels kc)
|
||||||
;; Let the channels start
|
(jupyter-hb-unpause (oref kc hb-channel))
|
||||||
(sleep-for 1)
|
(jupyter-start-kernel km)
|
||||||
(let ((info (jupyter-wait-until-received :kernel-info-reply
|
(condition-case nil
|
||||||
(jupyter-request-inhibit-handlers
|
(progn
|
||||||
(jupyter-kernel-info-request kc))
|
;; Wait for the startup message
|
||||||
10)))
|
(jupyter-wait-until-received :status (jupyter-missing-request kc) 10)
|
||||||
(if info (oset km kernel-info (jupyter-message-content info))
|
;; Remove the callback since the `jupyter-missing-request' does not go
|
||||||
(error "Kernel did not respond to kernel-info request.")))
|
;; through the normal request code path in `jupyter-kernel-client'
|
||||||
|
(setf (jupyter-request-callbacks (jupyter-missing-request kc)) nil)
|
||||||
|
(let ((info (jupyter-wait-until-received :kernel-info-reply
|
||||||
|
(jupyter-request-inhibit-handlers
|
||||||
|
(jupyter-kernel-info-request kc))
|
||||||
|
30)))
|
||||||
|
(if info (oset km kernel-info (jupyter-message-content info))
|
||||||
|
(error "Kernel did not respond to kernel-info request"))))
|
||||||
|
((error quit)
|
||||||
|
(jupyter-stop-channels kc)
|
||||||
|
(jupyter-stop-kernel km 0)))
|
||||||
(cons km kc)))
|
(cons km kc)))
|
||||||
|
|
||||||
(provide 'jupyter-kernel-manager)
|
(provide 'jupyter-kernel-manager)
|
||||||
|
|
Loading…
Add table
Reference in a new issue