Module: kernel.channels — IPython 2.3.1 documentation

### Navigation

- index
- modules |
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- The IPython API »

# Module: `kernel.channels`

Base classes to manage a Client’s interaction with a running kernel

## 6 Classes

class `IPython.kernel.channels.` `InvalidPortNumber`

  Bases: `exceptions.Exception`

class `IPython.kernel.channels.` `ZMQSocketChannel`(context, session, address)

  Bases: `threading.Thread`

  The base class for the channels that use ZMQ sockets.

  `__init__`(context, session, address)

    Create a channel.

    Parameters: | context : `zmq.Context` The ZMQ context to use. session : `session.Session` The session to use. address : zmq url Standard (ip, port) tuple that the kernel is listening on.

  `address`

    Get the channel’s address as a zmq url string.

    These URLS have the form: ‘tcp://127.0.0.1:5555‘.

  `stop`()

    Stop the channel’s event loop and join its thread.

    This calls `join()` and returns when the thread terminates. `RuntimeError` will be raised if `start()` is called again.

class `IPython.kernel.channels.` `ShellChannel`(context, session, address)

  Bases: `IPython.kernel.channels.ZMQSocketChannel`

  The shell channel for issuing request/replies to the kernel.

  `__init__`(context, session, address)
  `call_handlers`(msg)

    This method is called in the ioloop thread when a message arrives.

    Subclasses should override this method to handle incoming messages. It is important to remember that this method is called in the thread so that some logic must be done to ensure that the application level handlers are called in the application thread.

  `complete`(text, line, cursor_pos, block=None)

    Tab complete text in the kernel’s namespace.

    Parameters: | text : str The text to complete. line : str The full line of text that is the surrounding context for the text to complete. cursor_pos : int The position of the cursor in the line where the completion was requested. block : str, optional The full block of code in which the completion is being requested.
    Returns: | The msg_id of the message sent. :

  `execute`(code, silent=False, store_history=True, user_variables=None, user_expressions=None, allow_stdin=None)

    Execute code in the kernel.

    Parameters: | code : str A string of Python code. 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_variables : list, optional A list of variable names to pull from the user’s namespace. They will come back as a dict with these names as keys and their `repr()` as values. 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.
    Returns: | The msg_id of the message sent. :

  `history`(raw=True, output=False, hist_access_type='range', **kwargs)

    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.
    Returns: | The msg_id of the message sent. :

  `kernel_info`()

    Request kernel info.

  `object_info`(oname, detail_level=0)

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

    Parameters: | oname : str A string specifying the object name. detail_level : int, optional The level of detail for the introspection (0-2)
    Returns: | The msg_id of the message sent. :

  `run`()

    The thread’s main activity. Call start() instead.

  `shutdown`(restart=False)

    Request an immediate kernel shutdown.

    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.

class `IPython.kernel.channels.` `IOPubChannel`(context, session, address)

  Bases: `IPython.kernel.channels.ZMQSocketChannel`

  The iopub channel which listens for messages that the kernel publishes.

  This channel is where all output is published to frontends.

  `__init__`(context, session, address)
  `call_handlers`(msg)

    This method is called in the ioloop thread when a message arrives.

    Subclasses should override this method to handle incoming messages. It is important to remember that this method is called in the thread so that some logic must be done to ensure that the application leve handlers are called in the application thread.

  `flush`(timeout=1.0)

    Immediately processes all pending messages on the iopub channel.

    Callers should use this method to ensure that `call_handlers()` has been called for all messages that have been received on the 0MQ SUB socket of this channel.

    This method is thread safe.

    Parameters: | timeout : float, optional The maximum amount of time to spend flushing, in seconds. The default is one second.

  `run`()

    The thread’s main activity. Call start() instead.

class `IPython.kernel.channels.` `StdInChannel`(context, session, address)

  Bases: `IPython.kernel.channels.ZMQSocketChannel`

  The stdin channel to handle raw_input requests that the kernel makes.

  `__init__`(context, session, address)
  `call_handlers`(msg)

    This method is called in the ioloop thread when a message arrives.

    Subclasses should override this method to handle incoming messages. It is important to remember that this method is called in the thread so that some logic must be done to ensure that the application leve handlers are called in the application thread.

  `input`(string)

    Send a string of raw input to the kernel.

  `run`()

    The thread’s main activity. Call start() instead.

class `IPython.kernel.channels.` `HBChannel`(context, session, address)

  Bases: `IPython.kernel.channels.ZMQSocketChannel`

  The heartbeat channel which monitors the kernel heartbeat.

  Note that the heartbeat channel is paused by default. As long as you start this channel, the kernel manager will ensure that it is paused and un-paused as appropriate.

  `__init__`(context, session, address)
  `call_handlers`(since_last_heartbeat)

    This method is called in the ioloop thread when a message arrives.

    Subclasses should override this method to handle incoming messages. It is important to remember that this method is called in the thread so that some logic must be done to ensure that the application level handlers are called in the application thread.

  `is_beating`()

    Is the heartbeat running and responsive (and not paused).

  `pause`()

    Pause the heartbeat.

  `run`()

    The thread’s main activity. Call start() instead.

  `stop`()

    Stop the channel’s event loop and join its thread.

  `unpause`()

    Unpause the heartbeat.

## 2 Functions

`IPython.kernel.channels.` `validate_string_list`(lst)

  Validate that the input is a list of strings.

  Raises ValueError if not.

`IPython.kernel.channels.` `validate_string_dict`(dct)

  Validate that the input is a dict with string keys and values.

  Raises ValueError if not.

### Navigation

- index
- modules |
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- The IPython API »