Skip to content

Commit 2e86892

Browse files
committed
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.
1 parent 7d20c0a commit 2e86892

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

jupyter-base.el

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ from the kernel.")
117117
"MIME types that can be used in terminal Emacs.")
118118

119119
(defvar jupyter--debug nil
120-
"When non-nil, some parts of Jupyter will emit debug statements.")
120+
"When non-nil, some parts of Jupyter will emit debug statements.
121+
If the symbol 'message, messages received by a kernel will only
122+
be handled by clients when the function
123+
`jupyter--debug-run-message-queue' is called manually. This
124+
allows for stepping through the code with Edebug.")
121125

122126

123127
(defvar jupyter-default-timeout 2.5

jupyter-client.el

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,25 @@ back."
586586
(when jupyter--debug
587587
(jupyter--show-event event)))
588588

589+
(defvar jupyter--debug-message-queue nil)
590+
589591
(cl-defmethod jupyter-event-handler ((client jupyter-kernel-client)
590592
(event (head message)))
591593
(when jupyter--debug
592594
(jupyter--show-event event))
593-
(cl-destructuring-bind (_ channel _idents . msg) event
594-
(jupyter-handle-message client channel msg)))
595+
(if (eq jupyter--debug 'message)
596+
(push
597+
(cl-destructuring-bind (_ channel _idents . msg) event
598+
(lambda ()
599+
(jupyter-handle-message client channel msg)))
600+
jupyter--debug-message-queue)
601+
(cl-destructuring-bind (_ channel _idents . msg) event
602+
(jupyter-handle-message client channel msg))))
603+
604+
(defun jupyter--debug-run-message-queue ()
605+
(let ((queue (reverse jupyter--debug-message-queue)))
606+
(setq jupyter--debug-message-queue nil)
607+
(cl-loop for thunk in queue do (funcall thunk))))
595608

596609
;;; Starting communication with a kernel
597610

0 commit comments

Comments
 (0)