Proper implementation of #42, fix restart-kernel command.

Can jump to notebook cells from traceback buffer, kernel restart command
works on both IPython 2.x and 3.x.
This commit is contained in:
John Miller 2015-05-12 15:12:33 -05:00
parent 75c5f36ceb
commit d2681d88e3
2 changed files with 28 additions and 23 deletions

View file

@ -152,17 +152,19 @@
(defun ein:kernel-restart (kernel) (defun ein:kernel-restart (kernel)
(ein:events-trigger (ein:$kernel-events kernel) (ein:events-trigger (ein:$kernel-events kernel)
'status_restarting.Kernel) 'status_restarting.Kernel)
(ein:log 'info "Restarting kernel") (ein:log 'info "Restarting kernel - local settings will be lost!")
(when (ein:$kernel-running kernel) (when (ein:$kernel-running kernel)
(ein:kernel-stop kernel) (ein:kernel-stop kernel
(ein:query-singleton-ajax (apply-partially #'ein:kernel-start kernel (ein:get-notebook-or-error)))
(list 'kernel-restart (ein:$kernel-kernel-id kernel)) ;; (ein:query-singleton-ajax
(ein:url (ein:$kernel-url-or-port kernel) ;; (list 'kernel-restart (ein:$kernel-kernel-id kernel))
(ein:$kernel-kernel-url kernel) ;; (ein:url (ein:$kernel-url-or-port kernel)
"restart") ;; (ein:$kernel-kernel-url kernel)
:type "POST" ;; "restart")
:parser #'ein:json-read ;; :type "POST"
:success (apply-partially #'ein:kernel--kernel-started kernel)))) ;; :parser #'ein:json-read
;; :success (apply-partially #'ein:kernel--kernel-started kernel))
))
(defun* ein:kernel--kernel-started (kernel &key data &allow-other-keys) (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))) (ein:$kernel-after-start-hook kernel)))
(defun ein:kernel-stop (kernel) (defun ein:kernel-stop (kernel &optional callback)
(when (ein:$kernel-channels kernel) (when (ein:$kernel-channels kernel)
(setf (ein:$websocket-onclose (ein:$kernel-channels kernel)) nil) (setf (ein:$websocket-onclose (ein:$kernel-channels kernel)) nil)
(ein:websocket-close (ein:$kernel-channels kernel)) (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) (setf (ein:$websocket-onclose (ein:$kernel-iopub-channel kernel)) nil)
(ein:websocket-close (ein:$kernel-iopub-channel kernel)) (ein:websocket-close (ein:$kernel-iopub-channel kernel))
(setf (ein:$kernel-iopub-channel kernel) nil)) (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 (ein:query-singleton-ajax
(list 'session-delete (ein:$kernel-session-id kernel)) (list 'session-delete (ein:$kernel-session-id kernel))
(ein:url (ein:$kernel-url-or-port kernel) (ein:url (ein:$kernel-url-or-port kernel)
"api/sessions" "api/sessions"
(ein:$kernel-session-id kernel)) (ein:$kernel-session-id kernel))
:type "DELETE" :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))) :error (apply-partially #'ein:kernel--session-stopped-error kernel)))
(defun* ein:kernel--session-stopped-success (kernel &allow-other-keys) (defun* ein:kernel--session-stopped-success (kernel callback &key response &allow-other-keys)
(ein:log 'info "Stopped session %s." (ein:$kernel-session-id kernel))) (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) (defun* ein:kernel--session-stopped-error (kernel &key symbol-status response &allow-other-keys)
(ein:log 'verbose (ein:log 'verbose
"Error thrown: %S." (request-response-error-thrown response)) "Error thrown: %S." (request-response-error-thrown response))
(ein:log 'error (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) (defun ein:kernel-live-p (kernel)
(and (and

View file

@ -130,12 +130,12 @@
(cells (ein:worksheet-get-cells ws)) (cells (ein:worksheet-get-cells ws))
(it (find cellnum cells :key #'(lambda (x) (it (find cellnum cells :key #'(lambda (x)
(and (if (same-class-p x 'ein:codecell)
(slot-exists-p x :input-prompt-number) (oref x :input-prompt-number))))))
(slot-boundp x :input-prompt-number) (if it
(oref x :input-prompt-number)))))) (progn
(pop-to-buffer (ein:notebook-buffer nb)) (pop-to-buffer (ein:notebook-buffer nb))
(ein:cell-goto it)) (ein:cell-goto it))))
(progn (progn
(assert (file-exists-p file) nil "File %s does not exist." file) (assert (file-exists-p file) nil "File %s does not exist." file)
(let ((buf (find-file-noselect file)) (let ((buf (find-file-noselect file))