Skip to content

Commit

Permalink
Proper implementation of #42, fix restart-kernel command.
Browse files Browse the repository at this point in the history
Can jump to notebook cells from traceback buffer, kernel restart command
works on both IPython 2.x and 3.x.
  • Loading branch information
millejoh committed May 12, 2015
1 parent 75c5f36 commit d2681d8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
39 changes: 22 additions & 17 deletions lisp/ein-kernel.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lisp/ein-traceback.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit d2681d8

Please sign in to comment.