-
-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I reconnect a kernel whose websocket has been closed without restarting emacs? #526
Comments
I solved this issue using this function which can "forget" clients: (defun night/jupyter-forget-client (&optional key)
"Forget one or multiple Jupyter client sessions.
If KEY is provided, forget that specific session.
Otherwise, present a selection of all session keys to forget."
(interactive)
(if key
;; If a key is provided, forget that specific key.
(progn
(remhash key org-babel-jupyter-session-clients)
(message "Forgot session: %s" key))
;; If no key is provided, let the user select keys to forget.
(let ((keys (hash-table-keys org-babel-jupyter-session-clients)))
(ivy-read "Select sessions to forget: " keys
:action (lambda (selected)
(night/jupyter-forget-client selected))
:multi-action (lambda (selected)
(dolist (key selected)
(night/jupyter-forget-client key)))
:caller 'night/jupyter-forget-client)))) I can send this as a PR if you're interested. |
You can do something like (jupyter-reauthenticate-websockets (jupyter-current-server)) But this closes and then re-opens every websocket of every kernel for the current server. I'll have to come up with something that is more targeted for a specific client, e.g. re-establish the connection automatically if it's closed unintentionally. |
@nnicandro I actually need a way to "forget" a kernel completely. This is because I use a fixed local port I currently use this function, but it seems I am missing some stuff and not properly forgetting/closing everything. (defun night/jupyter-forget-client (key)
"Forget a Jupyter client session identified by KEY.
Also kill the associated REPL and object buffers.
@seeAlso `night/counsel-jupyter-forget-client'"
(interactive "sEnter session key to forget: ")
;; Remove the client from the `org-babel-jupyter-session-clients' hash table
(remhash key org-babel-jupyter-session-clients)
(when-let* ((client (gethash key org-babel-jupyter-session-clients)))
(let ((repl-buffer (oref client buffer)))
(message "got repl-buffer")
;; Kill the REPL buffer
(when t ;; (buffer-live-p repl-buffer)
(message "killing repl-buffer ...")
;; (kill-buffer repl-buffer)
;; If we use `kill-buffer', the kill hooks will be triggered which will ask us if we want to kill the kernel. We don't, we just want to clear the garbage and leave the kernel alone.
(night/force-kill-buffer repl-buffer))
;; Kill the object buffer
(jupyter-with-client-buffer client
(message "got client-buffer")
(when t ;; (buffer-live-p (current-buffer))
(message "killing client-buffer ...")
;; (kill-buffer (current-buffer))
(night/force-kill-current-buffer))))
(message "Forgot session: %s" key)))
(defun night/force-kill-current-buffer ()
(interactive)
;; [[https://emacs.stackexchange.com/questions/59348/force-kill-a-buffer][force kill a buffer? - Emacs Stack Exchange]]
(let (kill-buffer-hook kill-buffer-query-functions)
(kill-buffer)))
(defun night/force-kill-buffer (buffer)
(with-current-buffer buffer
(night/force-kill-current-buffer))) |
How do I reconnect a kernel whose websocket has been closed without restarting emacs?
I have:
so when I restart emacs, I can reconnect to this kernel just fine. The kernel is on a remote server, and I am using SSH port forwarding to access it on the localhost. Sometimes the SSH connection gets interrupted, and the websocket is closed. How do I reconnect in such cases without restarting emacs?
The text was updated successfully, but these errors were encountered: