mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-05 23:41:38 -05:00
Add kill-emacs-hook
functions for cleaning up clients and managers
If `kill-emacs` is called while the kernel process or client channel processes are still alive, the process sentinels do not run and thus the cleanup of the clients and managers does not happen. Thus we need to explicitly do this cleanup when `kill-emacs` is called.
This commit is contained in:
parent
7b68acbe69
commit
673747dc03
2 changed files with 22 additions and 2 deletions
|
@ -196,6 +196,13 @@ passed as the argument has a language of LANG."
|
||||||
(set-buffer-modified-p nil))
|
(set-buffer-modified-p nil))
|
||||||
(kill-buffer (oref client -buffer))))
|
(kill-buffer (oref client -buffer))))
|
||||||
|
|
||||||
|
(defun jupyter-kill-kernel-clients ()
|
||||||
|
"Call the destructor for all live Jupyter clients."
|
||||||
|
(dolist (client jupyter--clients)
|
||||||
|
(destructor client)))
|
||||||
|
|
||||||
|
(add-hook 'kill-emacs-hook 'jupyter-kill-kernel-clients)
|
||||||
|
|
||||||
(defun jupyter-find-client-for-session (session-id)
|
(defun jupyter-find-client-for-session (session-id)
|
||||||
"Return the `jupyter-kernel-client' for SESSION-ID."
|
"Return the `jupyter-kernel-client' for SESSION-ID."
|
||||||
(or (catch 'found
|
(or (catch 'found
|
||||||
|
|
|
@ -37,8 +37,13 @@
|
||||||
"Jupyter kernel manager"
|
"Jupyter kernel manager"
|
||||||
:group 'jupyter)
|
:group 'jupyter)
|
||||||
|
|
||||||
(defclass jupyter-kernel-manager ()
|
(defvar jupyter--managers nil
|
||||||
((name
|
"A list of all live kernel managers.
|
||||||
|
Managers are removed from this list when their `destructor' is called.")
|
||||||
|
|
||||||
|
(defclass jupyter-kernel-manager (eieio-instance-tracker)
|
||||||
|
((tracking-symbol :initform 'jupyter--managers)
|
||||||
|
(name
|
||||||
:initarg :name
|
:initarg :name
|
||||||
:type string
|
:type string
|
||||||
:documentation "The name of the kernel that is being managed.")
|
:documentation "The name of the kernel that is being managed.")
|
||||||
|
@ -81,8 +86,16 @@ default kernel is a python kernel."
|
||||||
;; See `jupyter--kernel-sentinel' for other cleanup
|
;; See `jupyter--kernel-sentinel' for other cleanup
|
||||||
(when (processp (oref manager kernel))
|
(when (processp (oref manager kernel))
|
||||||
(delete-process (oref manager kernel)))
|
(delete-process (oref manager kernel)))
|
||||||
|
(delete-instance manager)
|
||||||
(jupyter-stop-channels manager))
|
(jupyter-stop-channels manager))
|
||||||
|
|
||||||
|
(defun jupyter-kill-kernel-managers ()
|
||||||
|
(dolist (manager jupyter--managers)
|
||||||
|
(jupyter-shutdown-kernel manager)
|
||||||
|
(destructor manager)))
|
||||||
|
|
||||||
|
(add-hook 'kill-emacs-hook 'jupyter-kill-kernel-managers)
|
||||||
|
|
||||||
(cl-defgeneric jupyter-make-client ((manager jupyter-kernel-manager) class &rest slots)
|
(cl-defgeneric jupyter-make-client ((manager jupyter-kernel-manager) class &rest slots)
|
||||||
"Make a new client from CLASS connected to MANAGER's kernel.
|
"Make a new client from CLASS connected to MANAGER's kernel.
|
||||||
SLOTS are the slots used to initialize the client with.")
|
SLOTS are the slots used to initialize the client with.")
|
||||||
|
|
Loading…
Add table
Reference in a new issue