# The Frontend/Kernel Model¶

The traditional IPython (ipython) consists of a single process that combines a terminal based UI with the process that runs the users code.

While this traditional application still exists, the modern IPython consists of two processes:

• Kernel: this is the process that runs the users code.
• Frontend: this is the process that provides the user interface where the user types code and sees results.

IPython currently has 3 frontends:

• Terminal Console (ipython console)
• Qt Console (ipython qtconsole)
• Notebook (ipython notebook)

The Kernel and Frontend communicate over a ZeroMQ/JSON based messaging protocol, which allows multiple Frontends (even of different types) to communicate with a single Kernel. This opens the door for all sorts of interesting things, such as connecting a Console or Qt Console to a Notebook's Kernel. For example, you may want to connect a Qt console to your Notebook's Kernel and use it as a help browser, calling ?? on objects in the Qt console (whose pager is more flexible than the one in the notebook).

This Notebook describes how you would connect another Frontend to a Kernel that is associated with a Notebook.

## Manual connection¶

To connect another Frontend to a Kernel manually, you first need to find out the connection information for the Kernel using the %connect_info magic:

In [6]:
%connect_info

{
"stdin_port": 52858,
"ip": "127.0.0.1",
"hb_port": 52859,
"key": "7efd45ca-d8a2-41b0-9cea-d9116d0fb883",
"shell_port": 52856,
"iopub_port": 52857
}

Paste the above JSON into a file, and connect with:
$> ipython <app> --existing <file> or, if you are local, you can connect with just:$> ipython <app> --existing kernel-b3bac7c1-8b2c-4536-8082-8d1df24f99ac.json
or even just:
\$> ipython <app> --existing
if this is the most recent IPython session you have started.


You can see that this magic displays everything you need to connect to this Notebook's Kernel.

## Automatic connection using a new Qt Console¶

You can also start a new Qt Console connected to your current Kernel by using the %qtconsole magic. This will detect the necessary connection information and start the Qt Console for you automatically.

In [1]:
a = 10

In [2]:
%qtconsole


## The kernel's raw_input and %debug¶

The Notebook has added support for raw_input and %debug, as of 1.0.

In [1]:
# Python 3 compat
try:
raw_input
except NameError:
raw_input = input

In [2]:
name = raw_input("What is your name? ")
name

What is your name? Sir Robin

Out[2]:
'Sir Robin'

Python 2-only: the eval input works as well (input is just eval(raw_input(prompt)))

In [3]:
fingers = input("How many fingers? ")
fingers, type(fingers)

How many fingers? 4

Out[3]:
(4, int)
In [4]:
def div(x, y):
return x/y

div(1,0)

---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-4-a5097cc0c0c5> in <module>()
2     return x/y
3
----> 4 div(1,0)

<ipython-input-4-a5097cc0c0c5> in div(x, y)
1 def div(x, y):
----> 2     return x/y
3
4 div(1,0)

ZeroDivisionError: integer division or modulo by zero
In [5]:
%debug

> <ipython-input-4-a5097cc0c0c5>(2)div()
1 def div(x, y):
----> 2     return x/y
3

ipdb> x
1
ipdb> y
0
ipdb> exit