Construct a kernel object.
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.
The behavior is undefined if the message is modified during message handling. As such, the message should be treated as read-only.
The client unique id.
The id of the server-side kernel.
The cached kernel info.
This value will be null until the kernel is ready.
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.
Test whether the kernel is ready.
Get the model associated with the kernel.
The name of the server-side kernel.
A promise that is fulfilled when the kernel is ready.
The current status of the kernel.
A signal emitted when the kernel status changes.
A signal emitted when the kernel is shut down.
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.
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 socket state.
When calling this, you should also set the status to something like 'reconnecting' to reset the kernel ready state.
Clear the internal state.
Create the kernel websocket connection and add socket status handlers.
Handle 'comm_close' kernel message.
Handle a 'comm_msg' kernel message.
Handle a comm_open
kernel message.
Handle a message with a display id.
Whether the message was handled.
Handle a websocket close event.
Handle a websocket message, validating and routing appropriately.
Handle a websocket open event.
Send pending messages to the kernel.
Unregister a comm instance.
Handle status iopub messages from the kernel.
Clone the current kernel with a new clientId.
Connect to a comm, or create a new one.
If a client-side comm already exists with the given commId, it is returned.
Dispose of the resources held by the kernel.
Get the kernel spec.
A promise that resolves with the kernel spec.
Handle a restart on the kernel. This is not part of the IKernel
interface.
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 disconnected kernel.
Used when the websocket connection to the kernel is lost.
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.
The callback to remove.
The comm target is only removed the callback argument matches.
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.
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
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.
Restart a kernel.
Uses the Jupyter Notebook API and validates the response model.
Any existing Future or Comm objects are cleared.
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 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, closes the websocket and disposes of the kernel object, and fulfills the promise.
If the kernel is already dead
, it closes the websocket and returns
without a server request.
Connect to a running kernel.
The model of the running kernel.
The server settings for the request.
The kernel object.
If the kernel was already started via startNewKernel
, the existing
Kernel object info is used to create another instance.
Find a kernel by id.
The id of the kernel of interest.
The optional server settings.
A promise that resolves with the model for the kernel.
If the kernel was already started via startNewKernel
, we return its
Kernel.IModel
.
Otherwise, we attempt to find an existing kernel by connecting to the server. The promise is fulfilled when the kernel is found, otherwise the promise is rejected.
Fetch all of the kernel specs.
The optional server settings.
A promise that resolves with the kernel specs.
Uses the Jupyter Notebook API.
Fetch the running kernels.
The optional server settings.
A promise that resolves with the list of running kernels.
Uses the Jupyter Notebook API and validates the response model.
The promise is fulfilled on a valid response and rejected otherwise.
Shut down a kernel by id.
The id of the running kernel.
The server settings for the request.
A promise that resolves when the kernel is shut down.
Shut down all kernels.
The server settings to use.
A promise that resolves when all the kernels are shut down.
Start a new kernel.
The options used to create the kernel.
A promise that resolves with a kernel object.
Uses the Jupyter Notebook API and validates the response model.
If no options are given or the kernel name is not given, the default kernel will by started by the server.
Wraps the result in a Kernel object. The promise is fulfilled when the kernel is started by the server, otherwise the promise is rejected.
Generated using TypeDoc
Implementation of the Kernel object. The namespace for
DefaultKernel
statics.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.