Skip to main content
`Ctrl`+`K`

# jupyter_client.blocking package

## Submodules

Implements a fully blocking kernel client.

Useful for test suites and blocking terminal interfaces.

class jupyter_client.blocking.client.BlockingKernelClient(**kwargs)

  Bases: `KernelClient`

  A KernelClient with blocking APIs

  `get_[channel]_msg()` methods wait for and return messages on channels, raising `queue.Empty` if no message arrives within `timeout` seconds.

  comm_info(*args: Any, **kwargs: Any) → Any

    Request comm info

    Parameters:

      - reply (bool (default: False)) – Whether to wait for and return reply

      - timeout (float or None (default: None)) – Timeout to use when waiting for a reply

    Return type:

      `Any`

    Returns:

      - msg_id (str) – The msg_id of the request sent, if reply=False (default)

      - reply (dict) – The reply message for this request, if reply=True

  complete(*args: Any, **kwargs: Any) → Any

    Tab complete text in the kernel’s namespace.

    Parameters:

      - code (str) – The context in which completion is requested. Can be anything between a variable name and an entire cell.

      - cursor_pos (int, optional) – The position of the cursor in the block of code where the completion was requested. Default: `len(code)`

      - reply (bool (default: False)) – Whether to wait for and return reply

      - timeout (float or None (default: None)) – Timeout to use when waiting for a reply

    Return type:

      `Any`

    Returns:

      - msg_id (str) – The msg_id of the request sent, if reply=False (default)

      - reply (dict) – The reply message for this request, if reply=True

  control_channel_class

    A trait whose value must be a subclass of a specified class.

  execute(*args: Any, **kwargs: Any) → Any

    Execute code in the kernel.

    Parameters:

      - code (str) – A string of code in the kernel’s language.

      - silent (bool, optional (default False)) – If set, the kernel will execute the code as quietly possible, and will force store_history to be False.

      - store_history (bool, optional (default True)) – If set, the kernel will store command history. This is forced to be False if silent is True.

      - user_expressions (dict, optional) – A dict mapping names to expressions to be evaluated in the user’s dict. The expression values are returned as strings formatted using `repr()`.

      - allow_stdin (bool, optional (default self.allow_stdin)) –

        Flag for whether the kernel can send stdin requests to frontends.

        Some frontends (e.g. the Notebook) do not support stdin requests. If raw_input is called from code executed from such a frontend, a StdinNotImplementedError will be raised.

      - stop_on_error (bool, optional (default True)) – Flag whether to abort the execution queue, if an exception is encountered.

      - reply (bool (default: False)) – Whether to wait for and return reply

      - timeout (float or None (default: None)) – Timeout to use when waiting for a reply

    Return type:

      `Any`

    Returns:

      - msg_id (str) – The msg_id of the request sent, if reply=False (default)

      - reply (dict) – The reply message for this request, if reply=True

  execute_interactive(**kwargs: Any) → Any

    Execute code in the kernel interactively

    Output will be redisplayed, and stdin prompts will be relayed as well. If an IPython kernel is detected, rich output will be displayed.

    You can pass a custom output_hook callable that will be called with every IOPub message that is produced instead of the default redisplay.

    Added in version 5.0.

    Parameters:

      - code (str) – A string of code in the kernel’s language.

      - silent (bool, optional (default False)) – If set, the kernel will execute the code as quietly possible, and will force store_history to be False.

      - store_history (bool, optional (default True)) – If set, the kernel will store command history. This is forced to be False if silent is True.

      - user_expressions (dict, optional) – A dict mapping names to expressions to be evaluated in the user’s dict. The expression values are returned as strings formatted using `repr()`.

      - allow_stdin (bool, optional (default self.allow_stdin)) –

        Flag for whether the kernel can send stdin requests to frontends.

        Some frontends (e.g. the Notebook) do not support stdin requests. If raw_input is called from code executed from such a frontend, a StdinNotImplementedError will be raised.

      - stop_on_error (bool, optional (default True)) – Flag whether to abort the execution queue, if an exception is encountered.

      - timeout (float or None (default: None)) – Timeout to use when waiting for a reply

      - output_hook (callable(msg)) – Function to be called with output messages. If not specified, output will be redisplayed.

      - stdin_hook (callable(msg)) – Function or awaitable to be called with stdin_request messages. If not specified, input/getpass will be called.

    Returns:

      reply – The reply message for this request

    Return type:

      dict

  get_control_msg(**kwargs: Any) → Any

    Get a message from the control channel

    Return type:

      `Any`

  get_iopub_msg(**kwargs: Any) → Any

    Get a message from the iopub channel

    Return type:

      `Any`

  get_shell_msg(**kwargs: Any) → Any

    Get a message from the shell channel

    Return type:

      `Any`

  get_stdin_msg(**kwargs: Any) → Any

    Get a message from the stdin channel

    Return type:

      `Any`

  hb_channel_class

    A trait whose value must be a subclass of a specified class.

  history(*args: Any, **kwargs: Any) → Any

    Get entries from the kernel’s history list.

    Parameters:

      - raw (bool) – If True, return the raw input.

      - output (bool) – If True, then return the output as well.

      - hist_access_type (str) –

        ‘range’ (fill in session, start and stop params), ‘tail’ (fill in n)

          or ‘search’ (fill in pattern param).

      - session (int) – For a range request, the session from which to get lines. Session numbers are positive integers; negative ones count back from the current session.

      - start (int) – The first line number of a history range.

      - stop (int) – The final (excluded) line number of a history range.

      - n (int) – The number of lines of history to get for a tail request.

      - pattern (str) – The glob-syntax pattern for a search request.

      - reply (bool (default: False)) – Whether to wait for and return reply

      - timeout (float or None (default: None)) – Timeout to use when waiting for a reply

    Return type:

      `Any`

    Returns:

      - msg_id (str) – The msg_id of the request sent, if reply=False (default)

      - reply (dict) – The reply message for this request, if reply=True

  inspect(*args: Any, **kwargs: Any) → Any

    Get metadata information about an object in the kernel’s namespace.

    It is up to the kernel to determine the appropriate object to inspect.

    Parameters:

      - code (str) – The context in which info is requested. Can be anything between a variable name and an entire cell.

      - cursor_pos (int, optional) – The position of the cursor in the block of code where the info was requested. Default: `len(code)`

      - detail_level (int, optional) – The level of detail for the introspection (0-2)

      - reply (bool (default: False)) – Whether to wait for and return reply

      - timeout (float or None (default: None)) – Timeout to use when waiting for a reply

    Return type:

      `Any`

    Returns:

      - msg_id (str) – The msg_id of the request sent, if reply=False (default)

      - reply (dict) – The reply message for this request, if reply=True

  iopub_channel_class

    A trait whose value must be a subclass of a specified class.

  is_alive(**kwargs: Any) → Any

    Is the kernel process still running?

    Return type:

      `Any`

  kernel_info(*args: Any, **kwargs: Any) → Any

    Request kernel info

    Parameters:

      - reply (bool (default: False)) – Whether to wait for and return reply

      - timeout (float or None (default: None)) – Timeout to use when waiting for a reply

    Return type:

      `Any`

    Returns:

      - msg_id (str) – The msg_id of the request sent, if reply=False (default)

      - reply (dict) – The reply message for this request, if reply=True

  shell_channel_class

    A trait whose value must be a subclass of a specified class.

  shutdown(*args: Any, **kwargs: Any) → Any

    Request an immediate kernel shutdown on the control channel.

    Upon receipt of the (empty) reply, client code can safely assume that the kernel has shut down and it’s safe to forcefully terminate it if it’s still alive.

    The kernel will send the reply via a function registered with Python’s atexit module, ensuring it’s truly done as the kernel is done with all normal operation.

    Parameters:

      - reply (bool (default: False)) – Whether to wait for and return reply

      - timeout (float or None (default: None)) – Timeout to use when waiting for a reply

    Return type:

      `Any`

    Returns:

      - msg_id (str) – The msg_id of the request sent, if reply=False (default)

      - reply (dict) – The reply message for this request, if reply=True

  stdin_channel_class

    A trait whose value must be a subclass of a specified class.

  wait_for_ready(**kwargs: Any) → Any

    Waits for a response when a client is blocked

    - Sets future time for timeout

    - Blocks on shell channel until a message is received

    - Exit if the kernel has died

    - If client times out before receiving a message from the kernel, send RuntimeError

    - Flush the IOPub channel

    Return type:

      `Any`

jupyter_client.blocking.client.wrapped(meth, channel)

  Wrap a method on a channel and handle replies.

  Return type:

    `Callable`

## Module contents