emacs-jupyter/jupyter-kernel-manager.el

179 lines
6.2 KiB
EmacsLisp
Raw Normal View History

2018-01-08 21:38:32 -06:00
;;; jupyter-kernel-manager.el --- Jupyter kernel manager -*- lexical-binding: t -*-
2020-04-07 15:13:51 -05:00
;; Copyright (C) 2018-2020 Nathaniel Nicandro
2018-01-08 21:38:32 -06:00
2019-02-06 18:09:09 -06:00
;; Author: Nathaniel Nicandro <nathanielnicandro@gmail.com>
2018-01-08 21:38:32 -06:00
;; Created: 08 Jan 2018
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
2019-05-31 09:44:39 -05:00
;; published by the Free Software Foundation; either version 3, or (at
2018-01-08 21:38:32 -06:00
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Define interfaces for managing kernels.
2018-01-08 21:38:32 -06:00
;;; Code:
(require 'jupyter-base)
(require 'jupyter-env)
2018-01-08 21:38:32 -06:00
(require 'jupyter-messages)
(require 'jupyter-client)
(require 'jupyter-kernelspec)
Make `jupyter-channel-ioloop` independent of `zmq` This change localizes all `zmq` related functionality to `jupyter-ioloop` and `jupyter-zmq-*` files. * jupyter-channel-ioloop-comm.el: Add better commentary. (jupyter-base): Require. (jupyter-channel-ioloop-comm): Add `ioloop-class` slot (initialize-instance [jupyter-channel-ioloop-comm]): Use it. * jupyter-channel-ioloop.el (jupyter-base, jupyter-zmq-channel): Un-require. (jupyter-ioloop-session, jupyter-ioloop-channels): Rename to `jupyter-channel-ioloop-session` `jupyter-channel-ioloop-channels` and update all callers. (jupyter-channel-ioloop): Make into an abstract class. (initialize-instance [jupyter-channel-ioloop]): Re-add `jupyter-channel-ioloop-add-send-event`. Don't add to `jupyter-ioloop-post-hook`. (jupyter-channel-ioloop-recv-messages): Remove. (jupyter-channel-ioloop--set-session, jupyter-ioloop-start) (jupyter-channel-ioloop-add-send-event): Doc changes. (jupyter-channel-ioloop-add-start-channel-event) (jupyter-channel-ioloop-add-stop-channel-event): Don't add/remove from the `jupyter-ioloop-poller`. Now expected to be handled in the `jupyter-channel` subclass. Update documentation. In addition, for the start-channel event, do not attempt to add a channel if one doesn't already exist. * jupyter-ioloop.el (jupyter-ioloop-add-teardown): Remove mention of `jupyter-channel-ioloop` behavior. (jupyter-ioloop-add-arg-type): Update example variable. (jupyter-ioloop-environment-p): New function. * jupyter-kernel-manager.el (jupyter-channel): Require. (jupyter-make-client): Require and use `jupyter-zmq-channel-ioloop`. (jupyter-start-channels): Use `make-instance`. (jupyter-interrupt-kernel): Remove `condition-case`. Not needed since preventing socket blocking is now handled by `jupyter-recv`. * jupyter-repl.el (jupyter-connect-repl): Require and use `jupyter-zmq-channel-ioloop`. * jupyter-zmq-channel-ioloop.el: New file. * jupyter-zmq-channel.el (jupyter-ioloop-poller-remove) (jupyter-ioloop-poller-add): New declares. (jupyter-start-channel): Add to `jupyter-ioloop-poller` when in `jupyter-ioloop-environment-p`. (jupyter-stop-channel): Only disconnect the socket from its endpoint instead of closing it, leave that up to garbage collection. Remove from `jupyter-ioloop-poller` when in `jupyter-ioloop-environment-p`. (jupyter-recv): Handle non-blocking. * test/jupyter-test.el (jupyter-zmq-channel): Use non-blocking `zmq-send` since socket is no longer closed when calling `jupyter-stop-channel`. (jupyter-ioloop-test-eval-ioloop): Rename to `jupyter-test-ioloop-eval-event`, update all callers, and move to `test/test-helper.el`. (jupyter-channel-ioloop-send-event, jupyter-channel-ioloop-stop-channel-event) (jupyter-channel-ioloop-start-channel-event): Fix tests for variable name changes. Use `jupyter-test-channel-ioloop`. Update `jupyter-ioloop-poller`, addition/removal from poller is now done in the `jupyter-channel` subclass by checking `jupyter-ioloop-environment-p`. * test/test-helper.el (jupyter-zmq-channel-ioloop): Require. (initialize-instance [jupyter-echo-client]): Use it. (jupyter-test-channel-ioloop): New macro. (jupyter-test-ioloop-eval-event): New function.
2019-06-28 20:44:13 -05:00
(require 'jupyter-channel)
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
(eval-when-compile (require 'subr-x))
(declare-function ansi-color-apply "ansi-color" (string))
2018-01-08 21:38:32 -06:00
(defgroup jupyter-kernel-manager nil
"Jupyter kernel manager"
:group 'jupyter)
2018-01-08 21:38:32 -06:00
;;; `jupyter-kernel-lifetime'
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
(defclass jupyter-kernel-lifetime (jupyter-finalized-object)
()
:abstract t
:documentation "Interface to control the lifetime of a kernel.
Objects that implement this interface must implement the methods:
`jupyter-kernel-alive-p', `jupyter-start-kernel',
`jupyter-kill-kernel', and optionally `jupyter-kernel-died'.")
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
(cl-defmethod initialize-instance ((kernel jupyter-kernel-lifetime) &optional _slots)
"Setup a finalizer on KERNEL to kill it when KERNEL is garbage collected."
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
(cl-call-next-method)
(jupyter-add-finalizer kernel
(lambda ()
(when (jupyter-kernel-alive-p kernel)
(jupyter-kill-kernel kernel)))))
(cl-defgeneric jupyter-kernel-alive-p ((kernel jupyter-kernel-lifetime))
"Return non-nil if KERNEL is alive.")
(cl-defgeneric jupyter-start-kernel ((kernel jupyter-kernel-lifetime) &rest args)
"Start KERNEL.")
(cl-defgeneric jupyter-kill-kernel ((kernel jupyter-kernel-lifetime))
"Stop KERNEL.")
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
(cl-defgeneric jupyter-kernel-died ((kernel jupyter-kernel-lifetime))
"Called when a KERNEL dies unexpectedly.")
(cl-defmethod jupyter-start-kernel :around ((kernel jupyter-kernel-lifetime) &rest _args)
"Call the next method unless KERNEL is already alive."
(unless (jupyter-kernel-alive-p kernel)
(cl-call-next-method)))
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
(cl-defmethod jupyter-kill-kernel :around ((kernel jupyter-kernel-lifetime))
"Call the next method only when KERNEL is alive."
(when (jupyter-kernel-alive-p kernel)
(cl-call-next-method)))
(cl-defmethod jupyter-kernel-died ((_kernel jupyter-kernel-lifetime))
"Do nothing if KERNEL died."
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
(ignore))
;;; `jupyter-meta-kernel'
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
(defclass jupyter-meta-kernel (jupyter-kernel-lifetime)
((spec
:type cons
:initarg :spec
:documentation "The kernelspec for this kernel.
SPEC is in the same format as one of the elements returned by
`jupyter-find-kernelspecs'.")
(session
:type jupyter-session
:initarg :session
:documentation "The session used for communicating with the kernel."))
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
:abstract t
:documentation "Partial representation of a Jupyter kernel.
Contains the kernelspec associated with the kernel and the
`jupyter-session' object used for communicating with the kernel
when it is alive.
Sub-classes must call `cl-next-method-method' in their
implementation of `jupyter-kill-kernel'.
A convenience method, `jupyter-kernel-name', is provided to
access the name of the kernelspec.")
(cl-defmethod jupyter-kill-kernel ((_kernel jupyter-meta-kernel))
(ignore))
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
(cl-defmethod jupyter-kernel-name ((kernel jupyter-meta-kernel))
"Return the name of KERNEL."
(car (oref kernel spec)))
;;; `jupyter-kernel-manager'
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
2019-06-25 09:33:08 -05:00
(defvar jupyter--kernel-managers nil)
(defclass jupyter-kernel-manager (jupyter-kernel-lifetime
jupyter-instance-tracker)
((tracking-symbol :initform 'jupyter--kernel-managers)
(kernel
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
:type jupyter-meta-kernel
:initarg :kernel
:documentation "The kernel that is being managed."))
:abstract t)
2019-06-25 09:33:08 -05:00
(defun jupyter-kernel-managers ()
"Return a list of all `jupyter-kernel-manager' objects."
(jupyter-all-objects 'jupyter--kernel-managers))
(cl-defgeneric jupyter-make-client ((manager jupyter-kernel-manager) class &rest slots)
"Make a new client from CLASS connected to MANAGER's kernel.
SLOTS are the slots used to initialize the client with.")
(cl-defmethod jupyter-make-client :before (_manager class &rest _slots)
"Signal an error if CLASS is not a subclass of `jupyter-kernel-client'."
(unless (child-of-class-p class 'jupyter-kernel-client)
(signal 'wrong-type-argument (list '(subclass jupyter-kernel-client) class))))
(cl-defmethod jupyter-make-client (manager class &rest slots)
"Return an instance of CLASS using SLOTS and its manager slot set to MANAGER."
(let ((client (apply #'make-instance class slots)))
(prog1 client
(oset client manager manager))))
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
(cl-defmethod jupyter-start-kernel ((manager jupyter-kernel-manager) &rest args)
"Start MANAGER's kernel."
(unless (jupyter-kernel-alive-p manager)
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
(with-slots (kernel) manager
(apply #'jupyter-start-kernel kernel args)
(jupyter-start-channels manager))))
(cl-defgeneric jupyter-shutdown-kernel ((manager jupyter-kernel-manager) &rest args)
"Shutdown MANAGER's kernel or restart instead if RESTART is non-nil.
Wait until TIMEOUT before forcibly shutting down the kernel.")
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
(cl-defmethod jupyter-kill-kernel ((manager jupyter-kernel-manager))
(jupyter-shutdown-kernel manager))
(cl-defgeneric jupyter-interrupt-kernel ((manager jupyter-kernel-manager) &rest args)
"Interrupt MANAGER's kernel.
When the kernel has an interrupt mode of \"message\" send an
interrupt request and wait until TIMEOUT for a reply.")
(cl-defmethod jupyter-kernel-alive-p ((manager jupyter-kernel-manager))
"Is MANGER's kernel alive?"
Refactor of `jupyter-kernel-manager.el` This refactor implements a new class hierarchy to manage the lifetime of a Jupyter kernel. The first node in this hierarchy is the `jupyter-kernel-lifetime` class which defines a set of methods to manage the lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is stating that it has an association with a kernel and can be used to manage the lifetime of the associated kernel. The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and mainly defines a `spec` slot used to hold the `kernelspec` from which a command can be constructed to start a kernel and a `session` slot used to hold the `jupyter-session` object that clients can use to establish communication with a kernel once its live. Concrete classes that actually launch kernels are intended to inherit from this class and use its slots. `jupyter-kernel-process` manages the lifetime of a kernel started as a process using the function `start-file-process`, `jupyter-command-kernel` calls the `jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel` uses the `spec` slot to construct a shell command to start a kernel. A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a `jupyter-meta-kernel` and a `control-channel` slot and inherits from `jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager just defer to those of `kernel` while also taking into account the `control-channel`. * jupyter-base.el (jupyter-write-connection-file): New function. * jupyter-channel-ioloop.el (jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call. The startup message is not so important anymore. * jupyter-client.el (jupyter-wait-until-startup: New function. * jupyter-kernel-manager.el (jupyter-kernel-lifetime) (jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel) (jupyter-spec-kernel): New classes. (jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and implement its methods. (jupyter-kernel-manager--cleanup, jupyter-kernel-managers) (jupyter-delete-all-kernels, jupyter--kernel-sentinel) (jupyter--start-kernel): Remove and remove related, their functionality has been generalized in the new classes. (jupyter-interrupt-kernel, jupyter-shutdown-kernel) (jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p) (jupyter-kill-kernel): Refactor and implement to use the new class hierarchy. * test/jupyter-test.el: Refactor tests to account for changes. (jupyter-write-connect-file, jupyter-command-kernel): New tests. * jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 08:31:00 -05:00
(and (slot-boundp manager 'kernel)
(jupyter-kernel-alive-p (oref manager kernel))))
(provide 'jupyter-kernel-manager)
2018-01-08 21:38:32 -06:00
;;; jupyter-kernel-manager.el ends here