Implementation of the Kernel object.

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.

Implements

Constructors

Properties

handleComms: boolean

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.

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

serverSettings: ServerConnection.ISettings

The server settings for the kernel.

Accessors

  • get anyMessage(): ISignal<this, IAnyMessageArgs>
  • 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.

    Returns ISignal<this, IAnyMessageArgs>

  • get supportsSubshells(): boolean
  • Check if this kernel supports JEP 91 kernel subshells.

    Returns boolean

Methods

  • 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).

    Returns void

  • Register a comm target handler.

    Parameters

    • targetName: string

      The name of the comm target.

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

      The callback invoked for a comm open message.

    Returns void

    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.

    Parameters

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

      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]].

    Returns void

  • Remove a comm target handler.

    Parameters

    • targetName: string

      The name of the comm target to remove.

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

      The callback to remove.

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

    Returns void

  • 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]]

    Parameters

    • content: {
          allow_stdin?: boolean;
          code: string;
          silent?: boolean;
          stop_on_error?: boolean;
          store_history?: boolean;
          user_expressions?: JSONObject;
      }
      • Optionalallow_stdin?: boolean

        Whether to allow stdin requests. The default is true.

      • code: string

        The code to execute.

      • Optionalsilent?: boolean

        Whether to execute the code as quietly as possible. The default is false.

      • Optionalstop_on_error?: boolean

        Whether to the abort execution queue on an error. The default is false.

      • Optionalstore_history?: boolean

        Whether to store history of the execution. The default true if silent is False. It is forced to false if silent is true.

      • Optionaluser_expressions?: JSONObject

        A mapping of names to expressions to be evaluated in the kernel's interactive namespace.

    • disposeOnDone: boolean = true
    • Optionalmetadata: JSONObject

    Returns IShellFuture<IExecuteRequestMsg, IExecuteReplyMsg>

  • 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.

    Returns Promise<void>