##// END OF EJS Templates
notebook supports raw_input and %debug now...
MinRK -
Show More
@@ -1,157 +1,271 b''
1 1 {
2 2 "metadata": {
3 3 "name": "Frontend-Kernel Model"
4 4 },
5 5 "nbformat": 3,
6 6 "nbformat_minor": 0,
7 7 "worksheets": [
8 8 {
9 9 "cells": [
10 10 {
11 11 "cell_type": "heading",
12 12 "level": 1,
13 13 "metadata": {},
14 14 "source": [
15 15 "The Frontend/Kernel Model"
16 16 ]
17 17 },
18 18 {
19 19 "cell_type": "markdown",
20 20 "metadata": {},
21 21 "source": [
22 22 "The traditional IPython (`ipython`) consists of a single process that combines a terminal based UI with the process that runs the users code.\n",
23 23 "\n",
24 24 "While this traditional application still exists, the modern IPython consists of two processes:\n",
25 25 "\n",
26 26 "* Kernel: this is the process that runs the users code.\n",
27 27 "* Frontend: this is the process that provides the user interface where the user types code and sees results.\n",
28 28 "\n",
29 29 "IPython currently has 3 frontends:\n",
30 30 "\n",
31 31 "* Terminal Console (`ipython console`)\n",
32 32 "* Qt Console (`ipython qtconsole`)\n",
33 33 "* Notebook (`ipython notebook`)\n",
34 34 "\n",
35 35 "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\n",
36 36 "browser, calling `??` on objects in the Qt console (whose pager is more flexible than the\n",
37 37 "one in the notebook). \n",
38 38 "\n",
39 39 "This Notebook describes how you would connect another Frontend to a Kernel that is associated with a Notebook."
40 40 ]
41 41 },
42 42 {
43 43 "cell_type": "heading",
44 44 "level": 2,
45 45 "metadata": {},
46 46 "source": [
47 47 "Manual connection"
48 48 ]
49 49 },
50 50 {
51 51 "cell_type": "markdown",
52 52 "metadata": {},
53 53 "source": [
54 54 "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:"
55 55 ]
56 56 },
57 57 {
58 58 "cell_type": "code",
59 59 "collapsed": false,
60 60 "input": [
61 61 "%connect_info"
62 62 ],
63 63 "language": "python",
64 64 "metadata": {},
65 65 "outputs": [
66 66 {
67 67 "output_type": "stream",
68 68 "stream": "stdout",
69 69 "text": [
70 70 "{\n",
71 71 " \"stdin_port\": 52858, \n",
72 72 " \"ip\": \"127.0.0.1\", \n",
73 73 " \"hb_port\": 52859, \n",
74 74 " \"key\": \"7efd45ca-d8a2-41b0-9cea-d9116d0fb883\", \n",
75 75 " \"shell_port\": 52856, \n",
76 76 " \"iopub_port\": 52857\n",
77 77 "}\n",
78 78 "\n",
79 79 "Paste the above JSON into a file, and connect with:\n",
80 80 " $> ipython <app> --existing <file>\n",
81 81 "or, if you are local, you can connect with just:\n",
82 82 " $> ipython <app> --existing kernel-b3bac7c1-8b2c-4536-8082-8d1df24f99ac.json \n",
83 83 "or even just:\n",
84 84 " $> ipython <app> --existing \n",
85 85 "if this is the most recent IPython session you have started.\n"
86 86 ]
87 87 }
88 88 ],
89 89 "prompt_number": 6
90 90 },
91 91 {
92 92 "cell_type": "markdown",
93 93 "metadata": {},
94 94 "source": [
95 95 "You can see that this magic displays everything you need to connect to this Notebook's Kernel."
96 96 ]
97 97 },
98 98 {
99 99 "cell_type": "heading",
100 100 "level": 2,
101 101 "metadata": {},
102 102 "source": [
103 103 "Automatic connection using a new Qt Console"
104 104 ]
105 105 },
106 106 {
107 107 "cell_type": "markdown",
108 108 "metadata": {},
109 109 "source": [
110 110 "You can also start a new Qt Console connected to your current Kernel by using the `%qtconsole` magic. This will detect the necessary connection\n",
111 111 "information and start the Qt Console for you automatically."
112 112 ]
113 113 },
114 114 {
115 115 "cell_type": "code",
116 116 "collapsed": false,
117 117 "input": [
118 118 "a = 10"
119 119 ],
120 120 "language": "python",
121 121 "metadata": {},
122 122 "outputs": [],
123 123 "prompt_number": 1
124 124 },
125 125 {
126 126 "cell_type": "code",
127 127 "collapsed": false,
128 128 "input": [
129 129 "%qtconsole"
130 130 ],
131 131 "language": "python",
132 132 "metadata": {},
133 133 "outputs": [],
134 134 "prompt_number": 2
135 135 },
136 136 {
137 137 "cell_type": "heading",
138 138 "level": 2,
139 139 "metadata": {},
140 140 "source": [
141 141 "The kernel's `raw_input` and `%debug`"
142 142 ]
143 143 },
144 144 {
145 145 "cell_type": "markdown",
146 146 "metadata": {},
147 147 "source": [
148 "The one feature the notebook currently doesn't support as a Frontend is the ability to send data to the Kernel's standard input socket. That is, if the Kernel requires information to be typed interactively by calling the builtin `raw_input` function, the Notebook will be blocked. This happens for example if you run a script that queries interactively for parameters, and very importantly, is how the interactive IPython debugger that activates when you type `%debug` works.\n",
149 "\n",
150 "So, in order to be able to use `%debug` or anything else that requires `raw_input`, you can either use a Terminal Console or Qt Console connected to a Notebook's Kernel as described above.\n"
148 "The Notebook has added support for `raw_input` and `%debug`, as of 1.0."
151 149 ]
150 },
151 {
152 "cell_type": "code",
153 "collapsed": false,
154 "input": [
155 "name = raw_input(\"What is your name? \")\n",
156 "name"
157 ],
158 "language": "python",
159 "metadata": {},
160 "outputs": [
161 {
162 "name": "stdout",
163 "output_type": "stream",
164 "stream": "stdout",
165 "text": [
166 "What is your name? Sir Robin\n"
167 ]
168 },
169 {
170 "metadata": {},
171 "output_type": "pyout",
172 "prompt_number": 1,
173 "text": [
174 "u'Sir Robin'"
175 ]
176 }
177 ],
178 "prompt_number": 1
179 },
180 {
181 "cell_type": "code",
182 "collapsed": false,
183 "input": [
184 "def div(x, y):\n",
185 " return x/y\n",
186 "\n",
187 "div(1,0)"
188 ],
189 "language": "python",
190 "metadata": {},
191 "outputs": [
192 {
193 "ename": "ZeroDivisionError",
194 "evalue": "integer division or modulo by zero",
195 "output_type": "pyerr",
196 "traceback": [
197 "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)",
198 "\u001b[1;32m<ipython-input-2-a5097cc0c0c5>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mdiv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
199 "\u001b[1;32m<ipython-input-2-a5097cc0c0c5>\u001b[0m in \u001b[0;36mdiv\u001b[1;34m(x, y)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdiv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mdiv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
200 "\u001b[1;31mZeroDivisionError\u001b[0m: integer division or modulo by zero"
201 ]
202 }
203 ],
204 "prompt_number": 2
205 },
206 {
207 "cell_type": "code",
208 "collapsed": false,
209 "input": [
210 "%debug"
211 ],
212 "language": "python",
213 "metadata": {},
214 "outputs": [
215 {
216 "output_type": "stream",
217 "stream": "stdout",
218 "text": [
219 "> \u001b[1;32m<ipython-input-2-a5097cc0c0c5>\u001b[0m(2)\u001b[0;36mdiv\u001b[1;34m()\u001b[0m\n",
220 "\u001b[1;32m 1 \u001b[1;33m\u001b[1;32mdef\u001b[0m \u001b[0mdiv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
221 "\u001b[0m\u001b[1;32m----> 2 \u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
222 "\u001b[0m\u001b[1;32m 3 \u001b[1;33m\u001b[1;33m\u001b[0m\u001b[0m\n",
223 "\u001b[0m\n"
224 ]
225 },
226 {
227 "name": "stdout",
228 "output_type": "stream",
229 "stream": "stdout",
230 "text": [
231 "ipdb> x\n"
232 ]
233 },
234 {
235 "output_type": "stream",
236 "stream": "stdout",
237 "text": [
238 "1\n"
239 ]
240 },
241 {
242 "name": "stdout",
243 "output_type": "stream",
244 "stream": "stdout",
245 "text": [
246 "ipdb> y\n"
247 ]
248 },
249 {
250 "output_type": "stream",
251 "stream": "stdout",
252 "text": [
253 "0\n"
254 ]
255 },
256 {
257 "name": "stdout",
258 "output_type": "stream",
259 "stream": "stdout",
260 "text": [
261 "ipdb> exit\n"
262 ]
263 }
264 ],
265 "prompt_number": 3
152 266 }
153 267 ],
154 268 "metadata": {}
155 269 }
156 270 ]
157 271 } No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now