mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-05 23:41:38 -05:00
Move jupyter-wait-until-startup
to jupyter-kernel-manager.el
Also make `jupyter-wait-until-startup` private by renaming to `jupyter--wait-until-startup`. Startup messages are only sent once at kernel startup, since the only way to start a kernel is through a `jupyter-kernel-manager` it makes more sense to only allow a kernel manager to wait for a startup message.
This commit is contained in:
parent
1760d4942b
commit
a5d188e32f
2 changed files with 22 additions and 20 deletions
|
@ -683,25 +683,6 @@ that if no TIMEOUT is given, it defaults to
|
||||||
(declare (indent 1))
|
(declare (indent 1))
|
||||||
(jupyter-wait-until req msg-type #'identity timeout))
|
(jupyter-wait-until req msg-type #'identity timeout))
|
||||||
|
|
||||||
(defun jupyter-wait-until-startup (client &optional timeout)
|
|
||||||
"Wait until CLIENT receives a status: starting message.
|
|
||||||
Return the startup message if received by CLIENT within TIMEOUT
|
|
||||||
seconds otherwise return nil. TIMEOUT defaults to 1 s. Note that
|
|
||||||
there are no checks to determine if the kernel CLIENT is
|
|
||||||
connected to has already been started."
|
|
||||||
(let* ((started nil)
|
|
||||||
(cb (lambda (msg)
|
|
||||||
(setq started
|
|
||||||
(equal (jupyter-message-get msg :execution_state)
|
|
||||||
"starting"))))
|
|
||||||
(jupyter-include-other-output t))
|
|
||||||
(jupyter-add-hook client 'jupyter-iopub-message-hook cb)
|
|
||||||
(prog1
|
|
||||||
(with-timeout ((or timeout 1) nil)
|
|
||||||
(while (not started)
|
|
||||||
(sleep-for 0.01))
|
|
||||||
t)
|
|
||||||
(jupyter-remove-hook client 'jupyter-iopub-message-hook cb))))
|
|
||||||
|
|
||||||
(defun jupyter--drop-idle-requests (client)
|
(defun jupyter--drop-idle-requests (client)
|
||||||
(cl-loop
|
(cl-loop
|
||||||
|
|
|
@ -275,6 +275,26 @@ shutdown/interrupt requests"
|
||||||
(cl-defmethod jupyter-kernel-alive-p ((manager jupyter-kernel-manager))
|
(cl-defmethod jupyter-kernel-alive-p ((manager jupyter-kernel-manager))
|
||||||
(process-live-p (oref manager kernel)))
|
(process-live-p (oref manager kernel)))
|
||||||
|
|
||||||
|
(defun jupyter--wait-until-startup (client &optional timeout)
|
||||||
|
"Wait until CLIENT receives a status: starting message.
|
||||||
|
Return non-nil if the startup message was received by CLIENT
|
||||||
|
within TIMEOUT seconds otherwise return nil. TIMEOUT defaults to
|
||||||
|
1 s. Note that there are no checks to determine if the kernel
|
||||||
|
CLIENT is connected to has already been started."
|
||||||
|
(let* ((started nil)
|
||||||
|
(cb (lambda (msg)
|
||||||
|
(setq started
|
||||||
|
(equal (jupyter-message-get msg :execution_state)
|
||||||
|
"starting"))))
|
||||||
|
(jupyter-include-other-output t))
|
||||||
|
(jupyter-add-hook client 'jupyter-iopub-message-hook cb)
|
||||||
|
(prog1
|
||||||
|
(with-timeout ((or timeout 1) nil)
|
||||||
|
(while (not started)
|
||||||
|
(sleep-for 0.01))
|
||||||
|
t)
|
||||||
|
(jupyter-remove-hook client 'jupyter-iopub-message-hook cb))))
|
||||||
|
|
||||||
(defun jupyter-start-new-kernel (kernel-name &optional client-class)
|
(defun jupyter-start-new-kernel (kernel-name &optional client-class)
|
||||||
"Start a managed Jupyter kernel.
|
"Start a managed Jupyter kernel.
|
||||||
KERNEL-NAME is the name of the kernel to start. It can also be
|
KERNEL-NAME is the name of the kernel to start. It can also be
|
||||||
|
@ -302,7 +322,8 @@ listening and the heartbeat channel un-paused."
|
||||||
(jupyter-start-kernel km 10)
|
(jupyter-start-kernel km 10)
|
||||||
(condition-case nil
|
(condition-case nil
|
||||||
(progn
|
(progn
|
||||||
(jupyter-wait-until-startup kc 10)
|
(unless (jupyter--wait-until-startup kc 10)
|
||||||
|
(error "Kernel did not send startup message"))
|
||||||
(let ((info (jupyter-wait-until-received :kernel-info-reply
|
(let ((info (jupyter-wait-until-received :kernel-info-reply
|
||||||
(jupyter-request-inhibit-handlers
|
(jupyter-request-inhibit-handlers
|
||||||
(jupyter-kernel-info-request kc))
|
(jupyter-kernel-info-request kc))
|
||||||
|
|
Loading…
Add table
Reference in a new issue