Skip to content

Commit

Permalink
Improve support for allow_stdin and silent
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzchak committed Oct 15, 2024
1 parent e3fd986 commit 84f28ff
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
44 changes: 32 additions & 12 deletions src/kernel.lisp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
(in-package #:jupyter)

(defvar *enable-debugger* nil)
(defvar *stdout* nil)
(defvar *stdin* nil)
(defvar *stderr* nil)
(defvar *enable-debugger* t)
(defvar *enable-internal-debugger* t)
(defvar *payload* nil)
(defvar *markdown-output* nil)
(defvar *html-output* nil)
Expand Down Expand Up @@ -711,7 +715,8 @@
(mezzano.debug:*global-debugger* :external)
#+sbcl
(sb-ext:*invoke-debugger-hook* :external)
(t :internal)))
(*enable-internal-debugger* :internal)
(t :none)))

(defmacro with-debugger ((&key control internal) &body body)
(let ((debugger-hook (if control
Expand Down Expand Up @@ -942,9 +947,12 @@
(prog* ((shell (kernel-shell kernel))
(iopub (kernel-iopub kernel))
(*thread-id* (add-thread kernel))
(*standard-input* (kernel-standard-input kernel))
(*error-output* (kernel-error-output kernel))
(*standard-output* (kernel-standard-output kernel))
(*stdin* (kernel-standard-input kernel))
(*stdout* (kernel-standard-output kernel))
(*stderr* (kernel-error-output kernel))
(*standard-input* (make-synonym-stream '*stdin*))
(*standard-output* (make-synonym-stream '*stdout*))
(*error-output* (make-synonym-stream '*stderr*))
(*debug-io* (make-two-way-stream *standard-input* *standard-output*))
(*query-io* *debug-io*)
(*terminal-io* *debug-io*)
Expand Down Expand Up @@ -1495,13 +1503,25 @@
(inform :info *kernel* "Handling execute_request message")
(with-slots (execution-count history iopub package readtable input-queue breakpoints)
*kernel*
(let ((code (gethash "code" (message-content *message*)))
(ename "interrupt")
(evalue "Execution interrupted")
traceback
(*payload* (make-array 16 :adjustable t :fill-pointer 0))
(*page-output* (make-string-output-stream))
(*enable-debugger* (gethash "stop_on_error" (message-content *message*))))
(let* ((code (gethash "code" (message-content *message*)))
(silent (gethash "silent" (message-content *message*)))
(allow-stdin (gethash "allow_stdin" (message-content *message*)))
(ename "interrupt")
(evalue "Execution interrupted")
traceback
(*payload* (make-array 16 :adjustable t :fill-pointer 0))
(*page-output* (make-string-output-stream))
(*enable-debugger* (and (gethash "stop_on_error" (message-content *message*))
*enable-debugger*))
(*stderr* (if silent
(make-broadcast-stream)
*stderr*))
(*stdout* (if silent
(make-broadcast-stream)
*stdout*))
(*enable-internal-debugger* (and (not silent)
allow-stdin
*enable-internal-debugger*)))
(incf execution-count)
(add-cell history execution-count code)
(unwind-protect
Expand Down
8 changes: 8 additions & 0 deletions src/utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,11 @@
(equal ,ev-form ,(first clause)))
,@(cdr clause)))))
clauses))))))

#+ccl
(defmethod ccl::input-stream-shared-resource ((s synonym-stream))
(ccl::input-stream-shared-resource (symbol-value (synonym-stream-symbol s))))

#+ccl
(defmethod (setf ccl::input-stream-shared-resource) (new (s synonym-stream))
(setf (ccl::input-stream-shared-resource (symbol-value (synonym-stream-symbol s))) new))
2 changes: 2 additions & 0 deletions tests/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def test_execute_error(jupyter_kernel):
jupyter_kernel.execute_read_reply(
"(/ 1 0)",
timeout=10,
stop_on_error=False,
expected_reply=[{"content": {"status": "error", "ename": "DIVISION-BY-ZERO"}}],
)

Expand All @@ -203,6 +204,7 @@ def test_execute_result_error(jupyter_kernel):
(error "qux"))
(print (make-instance 'fu))""",
timeout=10,
stop_on_error=False,
expected_reply=[
{"content": {"status": "error", "ename": "SIMPLE-ERROR", "evalue": "qux"}}
],
Expand Down

0 comments on commit 84f28ff

Please sign in to comment.