diff --git a/lisp/ein-kernel.el b/lisp/ein-kernel.el index 2683c2720..1c0e858f8 100644 --- a/lisp/ein-kernel.el +++ b/lisp/ein-kernel.el @@ -152,17 +152,19 @@ (defun ein:kernel-restart (kernel) (ein:events-trigger (ein:$kernel-events kernel) 'status_restarting.Kernel) - (ein:log 'info "Restarting kernel") + (ein:log 'info "Restarting kernel - local settings will be lost!") (when (ein:$kernel-running kernel) - (ein:kernel-stop kernel) - (ein:query-singleton-ajax - (list 'kernel-restart (ein:$kernel-kernel-id kernel)) - (ein:url (ein:$kernel-url-or-port kernel) - (ein:$kernel-kernel-url kernel) - "restart") - :type "POST" - :parser #'ein:json-read - :success (apply-partially #'ein:kernel--kernel-started kernel)))) + (ein:kernel-stop kernel + (apply-partially #'ein:kernel-start kernel (ein:get-notebook-or-error))) + ;; (ein:query-singleton-ajax + ;; (list 'kernel-restart (ein:$kernel-kernel-id kernel)) + ;; (ein:url (ein:$kernel-url-or-port kernel) + ;; (ein:$kernel-kernel-url kernel) + ;; "restart") + ;; :type "POST" + ;; :parser #'ein:json-read + ;; :success (apply-partially #'ein:kernel--kernel-started kernel)) + )) (defun* ein:kernel--kernel-started (kernel &key data &allow-other-keys) @@ -324,7 +326,7 @@ See: https://github.com/ipython/ipython/pull/3307" (ein:$kernel-after-start-hook kernel))) -(defun ein:kernel-stop (kernel) +(defun ein:kernel-stop (kernel &optional callback) (when (ein:$kernel-channels kernel) (setf (ein:$websocket-onclose (ein:$kernel-channels kernel)) nil) (ein:websocket-close (ein:$kernel-channels kernel)) @@ -337,26 +339,29 @@ See: https://github.com/ipython/ipython/pull/3307" (setf (ein:$websocket-onclose (ein:$kernel-iopub-channel kernel)) nil) (ein:websocket-close (ein:$kernel-iopub-channel kernel)) (setf (ein:$kernel-iopub-channel kernel) nil)) - (ein:kernel-stop-session kernel)) + (ein:kernel-stop-session kernel callback)) -(defun ein:kernel-stop-session (kernel) +(defun ein:kernel-stop-session (kernel &optional callback) (ein:query-singleton-ajax (list 'session-delete (ein:$kernel-session-id kernel)) (ein:url (ein:$kernel-url-or-port kernel) "api/sessions" (ein:$kernel-session-id kernel)) :type "DELETE" - :success (apply-partially #'ein:kernel--session-stopped-success kernel) + :success (apply-partially #'ein:kernel--session-stopped-success kernel callback) :error (apply-partially #'ein:kernel--session-stopped-error kernel))) -(defun* ein:kernel--session-stopped-success (kernel &allow-other-keys) - (ein:log 'info "Stopped session %s." (ein:$kernel-session-id kernel))) +(defun* ein:kernel--session-stopped-success (kernel callback &key response &allow-other-keys) + (ein:log 'info "Stopped session %s." (ein:$kernel-session-id kernel)) + (setf (ein:$kernel-running kernel) nil) + (when callback + (funcall callback))) (defun* ein:kernel--session-stopped-error (kernel &key symbol-status response &allow-other-keys) (ein:log 'verbose "Error thrown: %S." (request-response-error-thrown response)) (ein:log 'error - "Failed to stop session %s with status %s." (ein:$kernel-session-id kernel) symbol-status)) + "Failed to stop session %s with status %s." (ein:$kernel-session-id kernel) (request-response-status-code response))) (defun ein:kernel-live-p (kernel) (and diff --git a/lisp/ein-traceback.el b/lisp/ein-traceback.el index 81d1f6abe..e9031f50c 100644 --- a/lisp/ein-traceback.el +++ b/lisp/ein-traceback.el @@ -130,12 +130,12 @@ (cells (ein:worksheet-get-cells ws)) (it (find cellnum cells :key #'(lambda (x) - (and - (slot-exists-p x :input-prompt-number) - (slot-boundp x :input-prompt-number) - (oref x :input-prompt-number)))))) - (pop-to-buffer (ein:notebook-buffer nb)) - (ein:cell-goto it)) + (if (same-class-p x 'ein:codecell) + (oref x :input-prompt-number)))))) + (if it + (progn + (pop-to-buffer (ein:notebook-buffer nb)) + (ein:cell-goto it)))) (progn (assert (file-exists-p file) nil "File %s does not exist." file) (let ((buf (find-file-noselect file))