Add a way to debug the message stream from a kernel

Previously it was hard to step through the code whenever messages were
coming in live from a kernel due to the asynchronous nature of
handling process output in Emacs.
This commit is contained in:
Nathaniel Nicandro 2022-01-07 15:07:30 -06:00
parent 7d20c0aee2
commit 2e8689227f
2 changed files with 20 additions and 3 deletions

View file

@ -117,7 +117,11 @@ from the kernel.")
"MIME types that can be used in terminal Emacs.")
(defvar jupyter--debug nil
"When non-nil, some parts of Jupyter will emit debug statements.")
"When non-nil, some parts of Jupyter will emit debug statements.
If the symbol 'message, messages received by a kernel will only
be handled by clients when the function
`jupyter--debug-run-message-queue' is called manually. This
allows for stepping through the code with Edebug.")
(defvar jupyter-default-timeout 2.5

View file

@ -586,12 +586,25 @@ back."
(when jupyter--debug
(jupyter--show-event event)))
(defvar jupyter--debug-message-queue nil)
(cl-defmethod jupyter-event-handler ((client jupyter-kernel-client)
(event (head message)))
(when jupyter--debug
(jupyter--show-event event))
(cl-destructuring-bind (_ channel _idents . msg) event
(jupyter-handle-message client channel msg)))
(if (eq jupyter--debug 'message)
(push
(cl-destructuring-bind (_ channel _idents . msg) event
(lambda ()
(jupyter-handle-message client channel msg)))
jupyter--debug-message-queue)
(cl-destructuring-bind (_ channel _idents . msg) event
(jupyter-handle-message client channel msg))))
(defun jupyter--debug-run-message-queue ()
(let ((queue (reverse jupyter--debug-message-queue)))
(setq jupyter--debug-message-queue nil)
(cl-loop for thunk in queue do (funcall thunk))))
;;; Starting communication with a kernel