IPython Documentation

Table Of Contents

Previous topic

lib.irunner

Next topic

lib.latextools

This Page

lib.kernel

Module: lib.kernel

Utilities for connecting to kernels

Authors:

  • Min Ragan-Kelley

Functions

IPython.lib.kernel.connect_qtconsole(connection_file=None, argv=None, profile=None)

Connect a qtconsole to the current kernel.

This is useful for connecting a second qtconsole to a kernel, or to a local notebook.

Parameters :

connection_file : str [optional]

The connection file to be used. Can be given by absolute path, or IPython will search in the security directory of a given profile. If run from IPython,

If unspecified, the connection file for the currently running IPython Kernel will be used, which is only allowed from inside a kernel.

argv : list [optional]

Any extra args to be passed to the console.

profile : str [optional]

The name of the profile to use when searching for the connection file, if different from the current IPython session or ‘default’.

Returns :

subprocess.Popen instance running the qtconsole frontend :

IPython.lib.kernel.find_connection_file(filename, profile=None)

find a connection file, and return its absolute path.

The current working directory and the profile’s security directory will be searched for the file if it is not given by absolute path.

If profile is unspecified, then the current running application’s profile will be used, or ‘default’, if not run from IPython.

If the argument does not match an existing file, it will be interpreted as a fileglob, and the matching file in the profile’s security dir with the latest access time will be used.

Parameters :

filename : str

The connection file or fileglob to search for.

profile : str [optional]

The name of the profile to use when searching for the connection file, if different from the current IPython session or ‘default’.

Returns :

str : The absolute path of the connection file.

IPython.lib.kernel.get_connection_file(app=None)

Return the path to the connection file of an app

Parameters :

app : KernelApp instance [optional]

If unspecified, the currently running app will be used

IPython.lib.kernel.get_connection_info(connection_file=None, unpack=False, profile=None)

Return the connection information for the current Kernel.

Parameters :

connection_file : str [optional]

The connection file to be used. Can be given by absolute path, or IPython will search in the security directory of a given profile. If run from IPython,

If unspecified, the connection file for the currently running IPython Kernel will be used, which is only allowed from inside a kernel.

unpack : bool [default: False]

if True, return the unpacked dict, otherwise just the string contents of the file.

profile : str [optional]

The name of the profile to use when searching for the connection file, if different from the current IPython session or ‘default’.

Returns :

The connection dictionary of the current kernel, as string or dict, :

depending on `unpack`. :

IPython.lib.kernel.swallow_argv(argv, aliases=None, flags=None)

strip frontend-specific aliases and flags from an argument list

For use primarily in frontend apps that want to pass a subset of command-line arguments through to a subprocess, where frontend-specific flags and aliases should be removed from the list.

Parameters :

argv : list(str)

The starting argv, to be filtered

aliases : container of aliases (dict, list, set, etc.)

The frontend-specific aliases to be removed

flags : container of flags (dict, list, set, etc.)

The frontend-specific flags to be removed

Returns :

argv : list(str)

The argv list, excluding flags and aliases that have been stripped

IPython.lib.kernel.tunnel_to_kernel(connection_info, sshserver, sshkey=None)

tunnel connections to a kernel via ssh

This will open four SSH tunnels from localhost on this machine to the ports associated with the kernel. They can be either direct localhost-localhost tunnels, or if an intermediate server is necessary, the kernel must be listening on a public IP.

Parameters :

connection_info : dict or str (path)

Either a connection dict, or the path to a JSON connection file

sshserver : str

The ssh sever to use to tunnel to the kernel. Can be a full user@server:port string. ssh config aliases are respected.

sshkey : str [optional]

Path to file containing ssh key to use for authentication. Only necessary if your ssh config does not already associate a keyfile with the host.

Returns :

(shell, iopub, stdin, hb) : ints

The four ports on localhost that have been forwarded to the kernel.