Construct a kernel object.
Private _anyPrivate _assertCheck 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.
Private _clearClear the internal state.
Private _clearForcefully 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.
Private _clientPrivate _commsPrivate _connectionPrivate _connectionPrivate _createCreate the kernel websocket connection and add socket status handlers.
Private _displayPrivate _disposedPrivate _errorUtility function to throw an error if this instance is disposed.
Private _futuresPrivate _handleHandle 'comm_close' kernel message.
Private _handleHandle a 'comm_msg' kernel message.
Private _handleHandle a comm_open kernel message.
Private _handleHandle a message with a display id.
Whether the message was handled.
Private _handlePrivate _hasPrivate _idPrivate _infoPrivate _iopubPrivate _isPrivate _kernelPrivate _modelPrivate _msgPrivate _msgPrivate _namePrivate _noPrivate _onWSCloseHandle a websocket close event.
Private _onWSMessageHandle a websocket message, validating and routing appropriately.
Private _onWSOpenHandle a websocket open event.
Private _pendingPrivate _pendingPrivate _reasonPrivate _reconnectAttempt a connection if we have not exhausted connection attempts.
Private _reconnectPrivate _reconnectPrivate _reconnectPrivate _selectedPrivate _sendPrivate _sendSend 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.
Private _sendSend pending messages to the kernel.
Private _specPrivate _statusPrivate _statusPrivate _supportedPrivate _targetPrivate _unhandledPrivate _unregisterUnregister a comm instance.
Private _updateHandle connection status changes.
Private _updateHandle status iopub messages from the kernel.
Private _usernamePrivate _wsWebsocket to communicate with kernel.
Readonly handleHandle 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.
Readonly serverThe 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.
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 name of the server-side kernel.
The kernel spec.
A promise that resolves to the kernel spec.
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.
Optional options: Pick<Kernel.IKernelConnection.IOptions, "username" | "clientId" | "handleComms">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).
Interrupt a kernel.
Uses the Jupyter Server 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.
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.
Send a comm_info_request message.
Fulfills with the comm_info_reply content when the shell reply is
received and validated.
Optional target_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]]
Optional allow_Whether to allow stdin requests.
The default is true.
The code to execute.
Optional silent?: booleanWhether to execute the code as quietly as possible.
The default is false.
Optional stop_Whether to the abort execution queue on an error.
The default is false.
Optional store_Whether to store history of the execution.
The default true if silent is False.
It is forced to false if silent is true.
Optional user_A mapping of names to expressions to be evaluated in the kernel's interactive namespace.
Optional disposeOnDone: booleanOptional metadata: JSONObjectSend 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 Server 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.
Optional expectReply: booleanOptional disposeOnDone: booleanSend 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.
Optional expectReply: booleanOptional disposeOnDone: booleanShutdown a kernel.
Uses the Jupyter Server 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.