Add jupyter--get-channel

This commit is contained in:
Nathaniel Nicandro 2018-02-03 19:10:30 -06:00
parent aa054178b7
commit 95a5cfbd74

View file

@ -518,6 +518,16 @@ in CLIENT."
(jupyter-stop-channel (oref client hb-channel)) (jupyter-stop-channel (oref client hb-channel))
(oset client ioloop nil)))) (oset client ioloop nil))))
(defun jupyter--get-channel (client ctype)
"Get CLIENT's channel based on CTYPE."
(cl-find-if
(lambda (channel) (eq (oref channel type) ctype))
(mapcar (lambda (sym) (slot-value client sym))
'(hb-channel
stdin-channel
shell-channel
iopub-channel))))
(defun jupyter--ioloop-filter (client event) (defun jupyter--ioloop-filter (client event)
"The process filter for CLIENT's ioloop subprocess. "The process filter for CLIENT's ioloop subprocess.
EVENT will be an s-expression emitted from the function returned EVENT will be an s-expression emitted from the function returned
@ -539,33 +549,15 @@ by `jupyter--ioloop'."
(jupyter-message-type msg) (jupyter-message-type msg)
(jupyter-message-parent-id msg) (jupyter-message-parent-id msg)
(jupyter-message-content msg))) (jupyter-message-content msg)))
(let ((channel (cl-loop (let ((channel (jupyter--get-channel client ctype)))
for c in '(stdin-channel
shell-channel
iopub-channel)
for channel = (slot-value client c)
when (eq (oref channel type) ctype)
return channel)))
(if (not channel) (warn "No handler for channel type (%s)" ctype) (if (not channel) (warn "No handler for channel type (%s)" ctype)
(jupyter-queue-message channel (cons idents msg)) (jupyter-queue-message channel (cons idents msg))
(run-with-timer 0.0001 nil #'jupyter-handle-message client channel)))) (run-with-timer 0.0001 nil #'jupyter-handle-message client channel))))
(`(start-channel ,ctype) (`(start-channel ,ctype)
(let ((channel (cl-loop (let ((channel (jupyter--get-channel client ctype)))
for c in '(stdin-channel
shell-channel
iopub-channel)
for channel = (slot-value client c)
when (eq (oref channel type) ctype)
return channel)))
(oset channel status 'running))) (oset channel status 'running)))
(`(stop-channel ,ctype) (`(stop-channel ,ctype)
(let ((channel (cl-loop (let ((channel (jupyter--get-channel client ctype)))
for c in '(stdin-channel
shell-channel
iopub-channel)
for channel = (slot-value client c)
when (eq (oref channel type) ctype)
return channel)))
(oset channel status 'stopped))) (oset channel status 'stopped)))
('(quit) ('(quit)
;; Cleanup handled in sentinel ;; Cleanup handled in sentinel
@ -598,7 +590,7 @@ would have to pass a nil value for the channel's key. As an
example, to prevent the control channel from starting you would example, to prevent the control channel from starting you would
call this function like so call this function like so
(jupyter-start-channels client :control nil) (jupyter-start-channels client :stdin nil)
In addition to calling `jupyter-start-channel', a subprocess is In addition to calling `jupyter-start-channel', a subprocess is
created for each channel which monitors the channel's socket for created for each channel which monitors the channel's socket for