Construct a kernel object.
Check to make sure it is okay to proceed to handle a message.
Because we handle messages asynchronously, before a message is handled the kernel might be disposed or restarted (and have a different session id). This function throws an error in each of these cases. This is meant to be called at the start of an asynchronous message handler to cancel message processing if the message no longer is valid.
Clear the internal state.
Forcefully clear the socket state.
This will clear all socket state without calling any handlers and will not update the connection status. If you call this method, you are responsible for updating the connection status as needed and recreating the socket if you plan to reconnect.
Create the kernel websocket connection and add socket status handlers.
Utility function to throw an error if this instance is disposed.
Handle 'comm_close' kernel message.
Handle a 'comm_msg' kernel message.
Handle a comm_open
kernel message.
Handle a message with a display id.
Handle a websocket close event.
Handle a websocket message, validating and routing appropriately.
Handle a websocket open event.
Attempt a connection if we have not exhausted connection attempts.
Send a message on the websocket.
If queue is true, queue the message for later sending if we cannot send now. Otherwise throw an error.
As an exception to the queueing, if we are sending a kernel_info_request message while we think the kernel is restarting, we send the message immediately without queueing. This is so that we can trigger a message back, which will then clear the kernel restarting state.
Send pending messages to the kernel.
Unregister a comm instance.
Handle connection status changes.
Handle status iopub messages from the kernel.
Websocket to communicate with kernel.
Handle comm messages
The comm message protocol currently has implicit assumptions that only one kernel connection is handling comm messages. This option allows a kernel connection to opt out of handling comms.
The server settings for the kernel.
A signal emitted for any kernel message.
This signal is emitted when a message is received, before it is handled asynchronously.
This message is emitted when a message is queued for sending (either in the websocket buffer, or our own pending message buffer). The message may actually be sent across the wire at a later time.
The message emitted in this signal should not be modified in any way.
The client unique id.
The current connection status of the kernel connection.
A signal emitted when the kernel status changes.
A signal emitted when the object is disposed.
Whether the kernel connection has pending input.
This is a guard to avoid deadlock is the user asks input as second time before submitting his first input
Whether the kernel connection has pending input.
This is a guard to avoid deadlock is the user asks input as second time before submitting his first input
The id of the server-side kernel.
The cached kernel info.
A promise that resolves to the kernel info.
A signal emitted for iopub kernel messages.
This signal is emitted after the iopub message is handled asynchronously.
Test whether the kernel has been disposed.
The kernel model
The name of the server-side kernel.
A signal emitted when a kernel has pending inputs from the user.
The kernel spec.
A promise that resolves to the kernel spec.
The current status of the kernel.
A signal emitted when the kernel status changes.
A signal emitted for unhandled kernel message.
This signal is emitted for a message that was not handled. It is emitted during the asynchronous message handling code.
The client username.
Clone the current kernel with a new clientId.
Dispose of the resources held by the kernel.
Handles a kernel shutdown.
This method should be called if we know from outside information that a kernel is dead (for example, we cannot find the kernel model on the server).
Check if a comm exists.
Interrupt a kernel.
Uses the Jupyter Notebook API.
The promise is fulfilled on a valid response and rejected otherwise.
It is assumed that the API call does not mutate the kernel id or name.
The promise will be rejected if the kernel status is Dead
or if the
request fails or the response is invalid.
Reconnect to a kernel.
This may try multiple times to reconnect to a kernel, and will sever any existing connection.
Register a comm target handler.
The name of the comm target.
The callback invoked for a comm open message.
A disposable used to unregister the comm target.
Only one comm target can be registered to a target name at a time, an
existing callback for the same target name will be overridden. A registered
comm target handler will take precedence over a comm which specifies a
target_module
.
If the callback returns a promise, kernel message processing will pause until the returned promise is fulfilled.
Register an IOPub message hook.
The callback invoked for the message.
The IOPub hook system allows you to preempt the handlers for IOPub messages that are responses to a given message id.
The most recently registered hook is run first. A hook can return a boolean or a promise to a boolean, in which case all kernel message processing pauses until the promise is fulfilled. If a hook return value resolves to false, any later hooks will not run and the function will return a promise resolving to false. If a hook throws an error, the error is logged to the console and the next hook is run. If a hook is registered during the hook processing, it will not run until the next message. If a hook is removed during the hook processing, it will be deactivated immediately.
See also IFuture.registerMessageHook.
Remove a comm target handler.
The name of the comm target to remove.
Remove the input guard, if any.
Remove an IOPub message hook.
The callback invoked for the message.
Send a comm_info_request
message.
Fulfills with the comm_info_reply
content when the shell reply is
received and validated.
The comm target name to filter returned comms
Send a complete_request
message.
See Messaging in Jupyter.
Fulfills with the complete_reply
content when the shell reply is
received and validated.
Send an execute_request
message.
See Messaging in Jupyter.
Future onReply
is called with the execute_reply
content when the
shell reply is received and validated. The future will resolve when
this message is received and the idle
iopub status is received.
The future will also be disposed at this point unless disposeOnDone
is specified and false
, in which case it is up to the caller to dispose
of the future.
See also: IExecuteReply
Whether to allow stdin requests.
The default is true
.
The code to execute.
Whether to execute the code as quietly as possible.
The default is false
.
Whether to the abort execution queue on an error.
The default is false
.
Whether to store history of the execution.
The default true
if silent is False.
It is forced to false
if silent is true
.
A mapping of names to expressions to be evaluated in the kernel's interactive namespace.
Send a history_request
message.
See Messaging in Jupyter.
Fulfills with the history_reply
content when the shell reply is
received and validated.
Send an inspect_request
message.
See Messaging in Jupyter.
Fulfills with the inspect_reply
content when the shell reply is
received and validated.
Send an is_complete_request
message.
See Messaging in Jupyter.
Fulfills with the is_complete_response
content when the shell reply is
received and validated.
Send a kernel_info_request
message.
See Messaging in Jupyter.
Fulfills with the kernel_info_response
content when the shell reply is
received and validated.
Request a kernel restart.
Uses the Jupyter Notebook API and validates the response model.
Any existing Future or Comm objects are cleared once the kernel has actually be restarted.
The promise is fulfilled on a valid server response (after the kernel restarts) and rejected otherwise.
It is assumed that the API call does not mutate the kernel id or name.
The promise will be rejected if the request fails or the response is invalid.
Send a control message to the kernel.
Send a message to the kernel's control channel, yielding a future object for accepting replies.
If expectReply
is given and true
, the future is disposed when both a
control reply and an idle status message are received. If expectReply
is not given or is false
, the future is resolved when an idle status
message is received.
If disposeOnDone
is not given or is true
, the Future is disposed at this point.
If disposeOnDone
is given and false
, it is up to the caller to dispose of the Future.
All replies are validated as valid kernel messages.
If the kernel status is dead
, this will throw an error.
Send a shell message to the kernel.
Send a message to the kernel's shell channel, yielding a future object for accepting replies.
If expectReply
is given and true
, the future is disposed when both a
shell reply and an idle status message are received. If expectReply
is not given or is false
, the future is resolved when an idle status
message is received.
If disposeOnDone
is not given or is true
, the Future is disposed at this point.
If disposeOnDone
is given and false
, it is up to the caller to dispose of the Future.
All replies are validated as valid kernel messages.
If the kernel status is dead
, this will throw an error.
Shutdown a kernel.
Uses the Jupyter Notebook API.
The promise is fulfilled on a valid response and rejected otherwise.
On a valid response, disposes this kernel connection.
If the kernel is already dead
, disposes this kernel connection without
a server request.
Generated using TypeDoc
Implementation of the Kernel object.
Notes
Messages from the server are handled in the order they were received and asynchronously. Any message handler can return a promise, and message handling will pause until the promise is fulfilled.