Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IKernelConnection

Interface of a Kernel connection that is managed by a session.

Notes

The Kernel object is tied to the lifetime of the Kernel id, which is a unique id for the Kernel session on the server. The Kernel object manages a websocket connection internally, and will auto-restart if the websocket temporarily loses connection. Restarting creates a new Kernel process on the server, but preserves the Kernel id.

The IKernelConnection is notably missing the full IKernel signals. This interface is for situations where a kernel may change, but we want a user to not have to worry about disconnecting and reconnecting signals when a kernel is swapped. The object that maintains an IKernel, but only provides a user with an IKernelConnection should proxy the appropriate IKernel signals for the user with its own signals. The advantage is that when the kernel is changed, the object itself can take care of disconnecting and reconnecting listeners.

Hierarchy

  • IObservableDisposable
    • IKernelConnection

Index

Properties

anyMessage

anyMessage: ISignal<this, IAnyMessageArgs>

A signal emitted when any kernel message is sent or received.

Notes

This signal is emitted before any message handling has happened. The message should be treated as read-only.

Readonly clientId

clientId: string

The client unique id.

Notes

This should be unique for a particular kernel connection object.

Readonly connectionStatus

connectionStatus: ConnectionStatus

The current connection status of the kernel.

connectionStatusChanged

connectionStatusChanged: ISignal<this, ConnectionStatus>

A signal emitted when the kernel connection status changes.

Readonly disposed

disposed: ISignal<this, void>

A signal emitted when the object is disposed.

handleComms

handleComms: boolean

Whether the kernel connection handles comm messages.

Notes

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.

See https://github.com/jupyter/jupyter_client/issues/263

Readonly id

id: string

The id of the server-side kernel.

Readonly info

info: Promise<IInfoReply>

The kernel info

Notes

This promise only resolves at startup, and is not refreshed on every restart.

iopubMessage

iopubMessage: ISignal<this, IIOPubMessage>

A signal emitted after an iopub kernel message is handled.

Readonly isDisposed

isDisposed: boolean

Test whether the object has been disposed.

Notes

This property is always safe to access.

Readonly model

model: IModel

The kernel model, for convenience.

Readonly name

name: string

The name of the server-side kernel.

Readonly serverSettings

serverSettings: ISettings

The server settings for the kernel.

Readonly spec

spec: Promise<ISpecModel | undefined>

Get the kernel spec.

returns

A promise that resolves with the kernel spec for this kernel.

Notes

This may make a server request to retrieve the spec.

Readonly status

status: Status

The current status of the kernel.

statusChanged

statusChanged: ISignal<this, Status>

A signal emitted when the kernel status changes.

unhandledMessage

unhandledMessage: ISignal<this, IMessage>

A signal emitted for unhandled non-iopub kernel messages that claimed to be responses for messages we sent using this kernel object.

Readonly username

username: string

The client username.

Methods

clone

  • Clone the current kernel with a new clientId.

    Parameters

    • Optional options: Pick<IOptions, "clientId" | "username" | "handleComms">

    Returns IKernelConnection

createComm

  • createComm(targetName: string, commId?: string): IComm
  • Create a new comm.

    Parameters

    • targetName: string

      The name of the comm target.

    • Optional commId: string

    Returns IComm

    A comm instance.

dispose

  • dispose(): void
  • Dispose of the resources held by the object.

    Notes

    If the object's dispose method is called more than once, all calls made after the first will be a no-op.

    Undefined Behavior

    It is undefined behavior to use any functionality of the object after it has been disposed unless otherwise explicitly noted.

    Returns void

hasComm

  • hasComm(commId: string): boolean
  • Check if a comm exists.

    Parameters

    • commId: string

    Returns boolean

interrupt

  • interrupt(): Promise<void>
  • Interrupt a kernel.

    Returns Promise<void>

    A promise that resolves when the kernel has interrupted.

    Notes

    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

  • reconnect(): Promise<void>
  • Reconnect to a disconnected kernel.

    Returns Promise<void>

    A promise that resolves when the kernel has reconnected.

    Notes

    This just refreshes the connection to an existing kernel, and does not perform an HTTP request to the server or restart the kernel.

registerCommTarget

  • registerCommTarget(targetName: string, callback: (comm: IComm, msg: ICommOpenMsg) => void | PromiseLike<void>): void
  • Register a comm target handler.

    Parameters

    • targetName: string

      The name of the comm target.

    • callback: (comm: IComm, msg: ICommOpenMsg) => void | PromiseLike<void>

      The callback invoked for a comm open message.

      Notes

      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.

    Returns void

registerMessageHook

  • registerMessageHook(msgId: string, hook: (msg: IIOPubMessage) => boolean | PromiseLike<boolean>): void
  • Register an IOPub message hook.

    Parameters

    • msgId: string
    • hook: (msg: IIOPubMessage) => boolean | PromiseLike<boolean>

      The callback invoked for the message.

      Notes

      The IOPub hook system allows you to preempt the handlers for IOPub messages with a given parent_header message id. The most recently registered hook is run first. If a hook return value resolves to false, any later hooks and the future's onIOPub handler will not run. 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 disposed during the hook processing, it will be deactivated immediately.

      See also IFuture.registerMessageHook.

    Returns void

removeCommTarget

  • removeCommTarget(targetName: string, callback: (comm: IComm, msg: ICommOpenMsg) => void | PromiseLike<void>): void
  • Remove a comm target handler.

    Parameters

    • targetName: string

      The name of the comm target to remove.

    • callback: (comm: IComm, msg: ICommOpenMsg) => void | PromiseLike<void>

      The callback to remove.

      Notes

      The comm target is only removed if it matches the callback argument.

    Returns void

removeMessageHook

  • removeMessageHook(msgId: string, hook: (msg: IIOPubMessage) => boolean | PromiseLike<boolean>): void
  • Remove an IOPub message hook.

    Parameters

    • msgId: string
    • hook: (msg: IIOPubMessage) => boolean | PromiseLike<boolean>

      The callback invoked for the message.

    Returns void

requestCommInfo

  • Send a comm_info_request message.

    Parameters

    Returns Promise<ICommInfoReplyMsg>

    A promise that resolves with the response message.

    Notes

    See Messaging in Jupyter.

    Fulfills with the comm_info_reply content when the shell reply is received and validated.

requestComplete

  • Send a complete_request message.

    Parameters

    Returns Promise<ICompleteReplyMsg>

    A promise that resolves with the response message.

    Notes

    See Messaging in Jupyter.

    Fulfills with the complete_reply content when the shell reply is received and validated.

requestExecute

  • Send an execute_request message.

    Parameters

    • content: IExecuteRequestMsg["content"]

      The content of the request.

    • Optional disposeOnDone: boolean

      Whether to dispose of the future when done.

    • Optional metadata: JSONObject

    Returns IShellFuture<IExecuteRequestMsg, IExecuteReplyMsg>

    A kernel future.

    Notes

    See Messaging in Jupyter.

    This method returns a kernel future, rather than a promise, since execution may have many response messages (for example, many iopub display messages).

    Future onReply is called with the execute_reply content when the shell reply is received and validated.

    See also: IExecuteReply

requestHistory

  • Send a history_request message.

    Parameters

    Returns Promise<IHistoryReplyMsg>

    A promise that resolves with the response message.

    Notes

    See Messaging in Jupyter.

    Fulfills with the history_reply content when the shell reply is received and validated.

requestInspect

  • Send an inspect_request message.

    Parameters

    Returns Promise<IInspectReplyMsg>

    A promise that resolves with the response message.

    Notes

    See Messaging in Jupyter.

    Fulfills with the inspect_reply content when the shell reply is received and validated.

requestIsComplete

  • Send an is_complete_request message.

    Parameters

    Returns Promise<IIsCompleteReplyMsg>

    A promise that resolves with the response message.

    Notes

    See Messaging in Jupyter.

    Fulfills with the is_complete_response content when the shell reply is received and validated.

requestKernelInfo

  • Send a kernel_info_request message.

    Returns Promise<IInfoReplyMsg | undefined>

    A promise that resolves with the response message.

    Notes

    See Messaging in Jupyter.

    Fulfills with the kernel_info_response content when the shell reply is received and validated.

restart

  • restart(): Promise<void>
  • Restart a kernel.

    Returns Promise<void>

    A promise that resolves when the kernel has restarted.

    Notes

    Uses the Jupyter Notebook API and validates the response model.

    Any existing Future or Comm objects are cleared.

    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.

sendControlMessage

sendInputReply

sendShellMessage

  • Send a shell message to the kernel.

    Type parameters

    Parameters

    • msg: IShellMessage<T>

      The fully-formed shell message to send.

    • Optional expectReply: boolean

      Whether to expect a shell reply message.

    • Optional disposeOnDone: boolean

      Whether to dispose of the future when done.

      Notes

      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 done when both a shell reply and an idle status message are received with the appropriate parent header, in which case the .done promise resolves to the reply. If expectReply is not given or is false, the future is done when an idle status message with the appropriate parent header is received, in which case the .done promise resolves to undefined.

      If disposeOnDone is given and false, the future will not be disposed of when the future is done, instead relying on the caller to dispose of it. This allows for the handling of out-of-order output from ill-behaved kernels.

      All replies are validated as valid kernel messages.

      If the kernel status is 'dead', this will throw an error.

    Returns IShellFuture<IShellMessage<T>>

shutdown

  • shutdown(): Promise<void>
  • Shutdown a kernel.

    Returns Promise<void>

    A promise that resolves when the kernel has shut down.

    Notes

    Uses the Jupyter Notebook API.

    On a valid response, closes the websocket, disposes of the kernel object, and fulfills the promise.

    The promise will be rejected if the kernel status is 'dead', the request fails, or the response is invalid.

Generated using TypeDoc