Commit graph

104 commits

Author SHA1 Message Date
Nathaniel Nicandro
f4bf16079d jupyter-start-kernel: Don't check access time of conn. file on Windows 2019-05-04 02:33:11 -05:00
Nathaniel Nicandro
b2294dceb2 Generalize communication with a kernel
The previous mechanism to communicate with a kernel was too low level from the
perspective of a client. The client interfaced directly with the subprocess
abstraction, `jupyter-ioloop`, and had to handle all "events" that occurred in
the `jupyter-ioloop`, e.g. when a channel was started or stopped. But in
reality such events should not be the concern of a client.

A client should only care about events that are directly related to kernel
messages and not events related to the implementation details of *how*
communication occurs.

This commit abstracts out the way in which a client communicates with its
kernel by introducing a new `jupyter-comm-layer` class. The
`jupyter-comm-layer` class takes care of managing the communication channel
between a kernel and its clients as well as sending events to all registered
clients. This way, clients operate solely at the level of events on the
communication layer. All a client does is register itself to receive events on
the communication layer and send events on the layer.

* jupyter-base.el (jupyter-session-endpoints): New function.

* jupyter-client.el (jupyter-kernel-client): Remove ioloop and channels slots.
  Add kcomm slot.
(initialize-instance): Unconditionally stop channels.
(jupyter-initialize-connection): Change into a method call.
Call `jupyter-initialize-connection` on the `kcomm` slot.
(jupyter-with-client-buffer): Remove stale comment.
(jupyter-send): Call `jupyter-send` on the `kcomm` slot.
(jupyter-ioloop-handler): Remove all method definitions, replace `sent` and
`message` methods with their `jupyter-event-handler` equivalents.
(jupyter-hb-pause, jupyter-hb-unpause, jupyter-hb-beating):
(jupyter-channel-alive-p, jupyter-start-channel, jupyter-stop-channel):
(jupyter-start-channels, jupyter-stop-channels):
Replace with calls to their equivalents using the `kcomm` slot.

* jupyter-comm-layer.el: New file.

* jupyter-kernel-manager (jupyter-make-client): Set a client's `kcomm` slot to
  `jupyter-channel-ioloop-comm`.

* jupyter-messages.el (jupyter-decode-message): Use `list` directly. There
  seemed to be issues when using the new `jupyter-sync-channel-comm` due to
  using quoted lists.

* test/jupyter-test.el: Add `jupyter-comm-layer` test. Update other tests.

* test/test-helper.el: Add `jupyter-comm-layer` mock objects. Update
  `jupyter-echo-client`.
2019-04-11 20:13:44 -05:00
Nathaniel Nicandro
89fb38da05
Add jupyter-error-if-not-client-class-p 2019-04-08 12:44:48 -05:00
Nathaniel Nicandro
ad5113b9a7
jupyter-start-kernel: Better error reporting during kernel startup
See https://github.com/dzop/emacs-jupyter/issues/70#issuecomment-476940527

* jupyter-kernel-manager.el
(jupyter--kernel-sentinel): Make ignored argument optional.
(jupyter--start-kernel): Don't set the process sentinel.
(jupyter-start-kernel): Report any errors after timeout.
Set the process sentinel as a last step.
2019-03-27 14:34:27 -05:00
Nathaniel Nicandro
c0c8ac7fae
jupyter-start-kernel: Error if no valid kernelspec could be found 2019-03-22 20:10:22 -05:00
Nathaniel Nicandro
ca64ff75c5
jupyter-start-kernel: Cleanup resources on a kernel restart
When a kernel restarts, `jupyter-start-kernel` will overwrite the slots
corresponding to external resources of the old, shutdown, kernel, like the
connection file. Ensure resources are cleaned up before overwriting those
slots.
2019-03-22 20:10:22 -05:00
Dan
8004ca188f guard against nil connection file in jupyter-kernel-manager--cleanup (#67) 2019-03-22 18:25:22 -05:00
Nathaniel Nicandro
83af335166
Bump version 2019-03-14 09:29:11 -05:00
Nathaniel Nicandro
6894a73d57
Cleanup stale comments 2019-03-07 22:51:25 -06:00
Nathaniel Nicandro
67a1d9ee1d
jupyter--start-kernel: Use de-structuring in loop body 2019-02-19 10:03:03 -06:00
Nathaniel Nicandro
d4969cbfcc CHANGELOG.org: Add function to change version numbers 2019-02-14 23:05:00 -06:00
Nathaniel Nicandro
4d37b0efea
jupyter-shutdown-kernel: Forcibly kill the kernel after timeout 2019-02-12 15:35:19 -06:00
Nathaniel Nicandro
63717b9e39
Bump version 2019-02-12 09:17:06 -06:00
Nathaniel Nicandro
647f32e405 jupyter-start-kernel: Ensure runtime directory exists
`make-temp-file` tries to read the `temporary-file-directory` and fails if it
does not exist yet so ensure that it does exist. Fixes #3.
2019-02-09 09:19:00 -06:00
Nathaniel Nicandro
0a34860707
Fix package-lint errors 2019-02-07 11:17:24 -06:00
Nathaniel Nicandro
771e267034
Fix checkdoc errors 2019-02-06 22:49:41 -06:00
Nathaniel Nicandro
39fba18b06
Update kernel restart process 2019-01-18 22:02:13 -06:00
Nathaniel Nicandro
c138d35b83
Remove stale comments 2019-01-17 20:45:45 -06:00
Nathaniel Nicandro
ac2b5ccfbe
jupyter-start-new-kernel: Use default wait time when starting the kernel
`jupyter-start-kernel` defaults to `jupyter-long-timeout` which already
defaults to 10 s.
2018-12-19 20:59:31 -06:00
Nathaniel Nicandro
7e42bdd80e
jupyter-start-kernel: Create jupyter-runtime-directory is necessary
Closes #3
2018-12-10 21:45:41 -06:00
Nathaniel Nicandro
1ecd029f6c More clearly show that an error occurs if no kernel info is received
* jupyter-kernel-manager.el (jupyter--error-if-no-kernel-info): New function.
(jupyter-start-new-kernel): Use it.
2018-11-17 11:47:55 -06:00
Nathaniel Nicandro
4842ac2198 jupyter-delete-all-kernels: Remove old cleanup
`jupyter-kernel-manager--cleanup` is intended to replace what was removed.
2018-11-17 11:47:55 -06:00
Nathaniel Nicandro
fbeb0dba0b jupyter-start-kernel: Handle all return values of file-attributes 2018-11-16 05:09:52 -06:00
Nathaniel Nicandro
081f329da1 v0.6.0 2018-11-16 00:27:47 -06:00
Nathaniel Nicandro
9097464cc8 Add jupyter-delete-all-kernels
Add this to `kill-emacs-hook` to ensure that connection files are cleaned up in
a more reliable fashion. The connection files are cleaned up when the kernel
process is garbage collected, but this won't happen when killing Emacs.

* jupyter-kernel-manager.el (jupyter-delete-all-kernels): Do it.
Add to `kill-emacs-hook`.
2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
823ea8adde Fix checkdoc warnings 2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
5a7c083169 More reliably capture the startup message
It still sometimes isn't caught but it is more reliable. This mainly affects
testing.

* jupyter-client.el (jupyter-start-channels): Add a small delay after starting
  channels.

* jupyter-kernel-manager.el (jupyter-start-kernel): Remove superfluous delay.
2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
c0e47165a9 Add instance tracker class
This is needed as opposed to eieio-instance-tracker so that we can create weak
references to objects. We don't want to have to manually delete an instance.

* jupyter-base.el (jupyter-instance-tracker): Do it.
(jupyter-all-objects): New function.

* jupyter-client.el (jupyter--clients): New variable.
(jupyter-kernel-client): Inherit from new class.
(jupyter-clients): Use jupyter-all-objects.

* jupyter-kernel-manager.el (jupyter-kernel-managers): New function.
2018-11-15 23:04:25 -06:00
Nathaniel Nicandro
134f84a59c Add object finalizer class
* jupyter-base.el (jupyter-finalized-object): New class.
(initialize-instance): New method addition.
(jupyter-add-finalizer): New method.

* jupyter-client.el (jupyter-kernel-client):
Inherit from jupyter-finalize-object.
(initialize-instance): Cleanup private buffer when client loses scope.
(jupyter-finalize): Remove.

* jupyter-kernel-manager.el (jupyter-kernel-manager):
Inherit from jupyter-finalized-instance.
(jupyter-kernl-manager--cleanup): New function.
(jupyter-finalize, jupyter-kill-kernel-managers): Remove. Update all callers.
(jupyter--kernel-sentinel): Remove MANAGER argument. Update all callers.
(jupyter--start-kernel): Remove MANAGER argument. Update all callers.
(jupyter-start-kernel): Add finalizer to kernel process to cleanup conn-file.

* jupyter-repl.el (jupyter-repl-kill-buffer-query-function):
Remove calls to jupyter-finalize.
2018-11-15 23:02:41 -06:00
Nathaniel Nicandro
3d45427eee jupyter-start-kernel: Use with-temp-file 2018-11-13 18:17:44 -06:00
Nathaniel Nicandro
9309e6c477 jupyter-start-channels: Simplify kernel manager method
* jupyter-kernel-manager: (jupyter-start-channels): Do it.
2018-11-13 18:17:44 -06:00
Nathaniel Nicandro
ff2feaab69 jupyter-shutdown-kernel: Report progress when shutting down 2018-11-13 17:47:55 -06:00
Nathaniel Nicandro
9aff88331a jupyter-start-new-kernel: Simplify
Remove the need to wrap in a progn. Un-pause heartbeat after waiting so that we
know for sure the kernel can be communicated with.
2018-11-13 17:47:55 -06:00
Nathaniel Nicandro
a82ae13438 Add jupyter-with-timeout macro
* jupyter-base.el (jupyter-default-timeout)
(jupyter-long-timeout): Moved from jupyter-client.el
(jupyter-with-timeout): Do it.

* jupyter-client.el (jupyter-wait-until): Use it.

* jupyter-kernel-manager.el (jupyter-shutdown-kernel)
(jupyter-interrupt-kernel, jupyter-start-new-kernel):
(jupyter-start-kernel): Use it.

use timeout
2018-11-13 17:46:19 -06:00
Nathaniel Nicandro
af32a3352f Promote the execution-state to be a slot of jupyter-kernel-client
* jupyter-client.el (jupyter-kernel-client): Do it.
(jupyter-run-hook-with-args-until-success): Pass client as first argument to
hooks.
(jupyter-execution-state): New convenience function.
(jupyter--set-execution-state): New helper function. Add as global IOPUB
message hook to set the execution-state slot.

* jupyter-repl.el (jupyter-repl-client): Remove execution-state slot.
(jupyter-handle-status): Don't set the execution-state slot.
(jupyter-repl-ret, jupyter-repl-interaction-mode-line): Use
jupyter-execution-state.
(jupyter-repl-initialize-hooks): Take into account changes to message hooks.

* jupyter-kernel-manager (jupyter-start-new-kernel): Update callback.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
2ae44ebcd6 jupyter--kernel-sentinel: Kill the process buffer when the kernel process is dead 2018-11-01 01:56:58 -05:00
Nathaniel Nicandro
91e766ed27 jupyter--kernel-sentinel: Use with-slots 2018-11-01 01:56:58 -05:00
Nathaniel Nicandro
890f5ab3cb Silence byte compiler
* Declare undeclared external functions

* Add ext: prefix to filename of external packages that may not be present on
  every system

* Remove `company-grab-symbol-cons` function declaration since this function is
  no longer used.
2018-10-27 22:16:54 -05:00
Nathaniel Nicandro
2f3f910598 Replace deprecated destructor method with jupyter-finalizer 2018-10-25 23:59:47 -05:00
Nathaniel Nicandro
673747dc03 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.
2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
c51d3b3a6c jupyter-start-kernel: Remove ANSI color codes in process output 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
6d3b326124 jupyter-shutdown-kernel: Fix wording of documentation 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
883197074e Move the kernel-info slot of jupyter-repl-client' to jupyter-kernel-client'
* Define new method `jupyter-kernel-info` which takes care
  of caching the result of a kernel info request. All
  access of the kernel info plist should happen through
  this method.

* Do not return the kernel info plist in
  `jupyter-start-new-kernel`, callers should access the
  kernel info through `jupyter-kernel-info`
2018-10-25 22:57:33 -05:00
Nathaniel Nicandro
c070f2d04d Update documentation and comments 2018-10-25 22:57:23 -05:00
Nathaniel Nicandro
c7c50f4908 Better error reporting when the kernel process dies in jupyter-start-kernel 2018-08-30 18:02:25 -05:00
Nathaniel Nicandro
22b1e809a0 Update documentation, cleanup comments 2018-08-30 18:02:13 -05:00
Nathaniel Nicandro
6e68a622cd Handle edge cases when starting a kernel and killing a REPL buffer
- Kill the REPL buffer without asking when the channels are closed

- Only emit a message if the kernel does not respond to a startup message
2018-05-28 01:25:33 -05:00
Nathaniel Nicandro
436089d08b Prefer defun over defsubst and other miscellaneous changes
- Add missing namespace to sha256 function

  - Any function defined should have a `jupyter-` prefix

- Remove `cl-lib` dependency in `jupyter-messages.el`

- Include `subr-x` in `jupyter-base.el`

- Use `tramp-file-name-user` instead of `tramp-file-name-real-user` since the
  latter is missing in Emacs 26
2018-05-28 01:25:33 -05:00
Nathaniel Nicandro
17596ee1c4 Be less ambiguous when encoding/decoding messages
- Do not handle nil as an empty dictionary when encoding.

- Use the default `json-array-type`
2018-05-28 01:25:09 -05:00
Nathaniel Nicandro
2f83bfd3ae Use jupyter-message-status-starting-p where appropriate 2018-05-20 11:03:06 -05:00