Show More
@@ -1,196 +1,191 b'' | |||||
1 | { |
|
1 | { | |
2 | "metadata": { |
|
2 | "metadata": { | |
3 | "name": "", |
|
3 | "name": "", | |
4 | "signature": "sha256:ac5c21534f3dd013c78d4d201527f3ed4dea5b6fad4116b8d23c67ba107e48c3" |
|
4 | "signature": "sha256:ac5c21534f3dd013c78d4d201527f3ed4dea5b6fad4116b8d23c67ba107e48c3" | |
5 | }, |
|
5 | }, | |
6 | "nbformat": 3, |
|
6 | "nbformat": 3, | |
7 | "nbformat_minor": 0, |
|
7 | "nbformat_minor": 0, | |
8 | "worksheets": [ |
|
8 | "worksheets": [ | |
9 | { |
|
9 | { | |
10 | "cells": [ |
|
10 | "cells": [ | |
11 | { |
|
11 | { | |
12 | "cell_type": "heading", |
|
12 | "cell_type": "heading", | |
13 | "level": 1, |
|
13 | "level": 1, | |
14 | "metadata": {}, |
|
14 | "metadata": {}, | |
15 | "source": [ |
|
15 | "source": [ | |
16 | "Using `raw_input` and `%debug` in the Notebook" |
|
16 | "Using `raw_input` and `%debug` in the Notebook" | |
17 | ] |
|
17 | ] | |
18 | }, |
|
18 | }, | |
19 | { |
|
19 | { | |
20 | "cell_type": "markdown", |
|
20 | "cell_type": "markdown", | |
21 | "metadata": {}, |
|
21 | "metadata": {}, | |
22 | "source": [ |
|
22 | "source": [ | |
23 | "The Notebook has added support for `raw_input` and `%debug`, as of 1.0." |
|
23 | "The Notebook has added support for `raw_input` and `%debug`, as of 1.0." | |
24 | ] |
|
24 | ] | |
25 | }, |
|
25 | }, | |
26 | { |
|
26 | { | |
27 | "cell_type": "code", |
|
27 | "cell_type": "code", | |
28 | "collapsed": false, |
|
28 | "collapsed": false, | |
29 | "input": [ |
|
29 | "input": [ | |
30 | "# Python 3 compat\n", |
|
30 | "# Python 3 compat\n", | |
31 | "import sys\n", |
|
31 | "import sys\n", | |
32 | "if sys.version_info[0] >= 3:\n", |
|
32 | "if sys.version_info[0] >= 3:\n", | |
33 | " raw_input = input" |
|
33 | " raw_input = input" | |
34 | ], |
|
34 | ], | |
35 | "language": "python", |
|
35 | "language": "python", | |
36 | "metadata": {}, |
|
36 | "metadata": {}, | |
37 | "outputs": [], |
|
37 | "outputs": [], | |
38 | "prompt_number": 1 |
|
38 | "prompt_number": 1 | |
39 | }, |
|
39 | }, | |
40 | { |
|
40 | { | |
41 | "cell_type": "code", |
|
41 | "cell_type": "code", | |
42 | "collapsed": false, |
|
42 | "collapsed": false, | |
43 | "input": [ |
|
43 | "input": [ | |
44 | "name = raw_input(\"What is your name? \")\n", |
|
44 | "name = raw_input(\"What is your name? \")\n", | |
45 | "name" |
|
45 | "name" | |
46 | ], |
|
46 | ], | |
47 | "language": "python", |
|
47 | "language": "python", | |
48 | "metadata": {}, |
|
48 | "metadata": {}, | |
49 | "outputs": [ |
|
49 | "outputs": [ | |
50 | { |
|
50 | { | |
51 | "name": "stdout", |
|
|||
52 | "output_type": "stream", |
|
51 | "output_type": "stream", | |
53 | "stream": "stdout", |
|
52 | "stream": "stdout", | |
54 | "text": [ |
|
53 | "text": [ | |
55 | "What is your name? Sir Robin\n" |
|
54 | "What is your name? Sir Robin\n" | |
56 | ] |
|
55 | ] | |
57 | }, |
|
56 | }, | |
58 | { |
|
57 | { | |
59 | "metadata": {}, |
|
58 | "metadata": {}, | |
60 | "output_type": "pyout", |
|
59 | "output_type": "pyout", | |
61 | "prompt_number": 2, |
|
60 | "prompt_number": 2, | |
62 | "text": [ |
|
61 | "text": [ | |
63 | "'Sir Robin'" |
|
62 | "'Sir Robin'" | |
64 | ] |
|
63 | ] | |
65 | } |
|
64 | } | |
66 | ], |
|
65 | ], | |
67 | "prompt_number": 2 |
|
66 | "prompt_number": 2 | |
68 | }, |
|
67 | }, | |
69 | { |
|
68 | { | |
70 | "cell_type": "markdown", |
|
69 | "cell_type": "markdown", | |
71 | "metadata": {}, |
|
70 | "metadata": {}, | |
72 | "source": [ |
|
71 | "source": [ | |
73 | "**Python 2-only**: the eval input works as well (`input` is just `eval(raw_input(prompt))`)" |
|
72 | "**Python 2-only**: the eval input works as well (`input` is just `eval(raw_input(prompt))`)" | |
74 | ] |
|
73 | ] | |
75 | }, |
|
74 | }, | |
76 | { |
|
75 | { | |
77 | "cell_type": "code", |
|
76 | "cell_type": "code", | |
78 | "collapsed": false, |
|
77 | "collapsed": false, | |
79 | "input": [ |
|
78 | "input": [ | |
80 | "fingers = input(\"How many fingers? \")\n", |
|
79 | "fingers = input(\"How many fingers? \")\n", | |
81 | "fingers, type(fingers)" |
|
80 | "fingers, type(fingers)" | |
82 | ], |
|
81 | ], | |
83 | "language": "python", |
|
82 | "language": "python", | |
84 | "metadata": {}, |
|
83 | "metadata": {}, | |
85 | "outputs": [ |
|
84 | "outputs": [ | |
86 | { |
|
85 | { | |
87 | "name": "stdout", |
|
|||
88 | "output_type": "stream", |
|
86 | "output_type": "stream", | |
89 | "stream": "stdout", |
|
87 | "stream": "stdout", | |
90 | "text": [ |
|
88 | "text": [ | |
91 | "How many fingers? 4\n" |
|
89 | "How many fingers? 4\n" | |
92 | ] |
|
90 | ] | |
93 | }, |
|
91 | }, | |
94 | { |
|
92 | { | |
95 | "metadata": {}, |
|
93 | "metadata": {}, | |
96 | "output_type": "pyout", |
|
94 | "output_type": "pyout", | |
97 | "prompt_number": 3, |
|
95 | "prompt_number": 3, | |
98 | "text": [ |
|
96 | "text": [ | |
99 | "(4, int)" |
|
97 | "(4, int)" | |
100 | ] |
|
98 | ] | |
101 | } |
|
99 | } | |
102 | ], |
|
100 | ], | |
103 | "prompt_number": 3 |
|
101 | "prompt_number": 3 | |
104 | }, |
|
102 | }, | |
105 | { |
|
103 | { | |
106 | "cell_type": "code", |
|
104 | "cell_type": "code", | |
107 | "collapsed": false, |
|
105 | "collapsed": false, | |
108 | "input": [ |
|
106 | "input": [ | |
109 | "def div(x, y):\n", |
|
107 | "def div(x, y):\n", | |
110 | " return x/y\n", |
|
108 | " return x/y\n", | |
111 | "\n", |
|
109 | "\n", | |
112 | "div(1,0)" |
|
110 | "div(1,0)" | |
113 | ], |
|
111 | ], | |
114 | "language": "python", |
|
112 | "language": "python", | |
115 | "metadata": {}, |
|
113 | "metadata": {}, | |
116 | "outputs": [ |
|
114 | "outputs": [ | |
117 | { |
|
115 | { | |
118 | "ename": "ZeroDivisionError", |
|
116 | "ename": "ZeroDivisionError", | |
119 | "evalue": "integer division or modulo by zero", |
|
117 | "evalue": "integer division or modulo by zero", | |
120 | "output_type": "pyerr", |
|
118 | "output_type": "pyerr", | |
121 | "traceback": [ |
|
119 | "traceback": [ | |
122 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", |
|
120 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", | |
123 | "\u001b[1;32m<ipython-input-4-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", |
|
121 | "\u001b[1;32m<ipython-input-4-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", | |
124 | "\u001b[1;32m<ipython-input-4-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", |
|
122 | "\u001b[1;32m<ipython-input-4-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", | |
125 | "\u001b[1;31mZeroDivisionError\u001b[0m: integer division or modulo by zero" |
|
123 | "\u001b[1;31mZeroDivisionError\u001b[0m: integer division or modulo by zero" | |
126 | ] |
|
124 | ] | |
127 | } |
|
125 | } | |
128 | ], |
|
126 | ], | |
129 | "prompt_number": 4 |
|
127 | "prompt_number": 4 | |
130 | }, |
|
128 | }, | |
131 | { |
|
129 | { | |
132 | "cell_type": "code", |
|
130 | "cell_type": "code", | |
133 | "collapsed": false, |
|
131 | "collapsed": false, | |
134 | "input": [ |
|
132 | "input": [ | |
135 | "%debug" |
|
133 | "%debug" | |
136 | ], |
|
134 | ], | |
137 | "language": "python", |
|
135 | "language": "python", | |
138 | "metadata": {}, |
|
136 | "metadata": {}, | |
139 | "outputs": [ |
|
137 | "outputs": [ | |
140 | { |
|
138 | { | |
141 | "output_type": "stream", |
|
139 | "output_type": "stream", | |
142 | "stream": "stdout", |
|
140 | "stream": "stdout", | |
143 | "text": [ |
|
141 | "text": [ | |
144 | "> \u001b[1;32m<ipython-input-4-a5097cc0c0c5>\u001b[0m(2)\u001b[0;36mdiv\u001b[1;34m()\u001b[0m\n", |
|
142 | "> \u001b[1;32m<ipython-input-4-a5097cc0c0c5>\u001b[0m(2)\u001b[0;36mdiv\u001b[1;34m()\u001b[0m\n", | |
145 | "\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", |
|
143 | "\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", | |
146 | "\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", |
|
144 | "\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", | |
147 | "\u001b[0m\u001b[1;32m 3 \u001b[1;33m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
145 | "\u001b[0m\u001b[1;32m 3 \u001b[1;33m\u001b[1;33m\u001b[0m\u001b[0m\n", | |
148 | "\u001b[0m\n" |
|
146 | "\u001b[0m\n" | |
149 | ] |
|
147 | ] | |
150 | }, |
|
148 | }, | |
151 | { |
|
149 | { | |
152 | "name": "stdout", |
|
|||
153 | "output_type": "stream", |
|
150 | "output_type": "stream", | |
154 | "stream": "stdout", |
|
151 | "stream": "stdout", | |
155 | "text": [ |
|
152 | "text": [ | |
156 | "ipdb> x\n" |
|
153 | "ipdb> x\n" | |
157 | ] |
|
154 | ] | |
158 | }, |
|
155 | }, | |
159 | { |
|
156 | { | |
160 | "output_type": "stream", |
|
157 | "output_type": "stream", | |
161 | "stream": "stdout", |
|
158 | "stream": "stdout", | |
162 | "text": [ |
|
159 | "text": [ | |
163 | "1\n" |
|
160 | "1\n" | |
164 | ] |
|
161 | ] | |
165 | }, |
|
162 | }, | |
166 | { |
|
163 | { | |
167 | "name": "stdout", |
|
|||
168 | "output_type": "stream", |
|
164 | "output_type": "stream", | |
169 | "stream": "stdout", |
|
165 | "stream": "stdout", | |
170 | "text": [ |
|
166 | "text": [ | |
171 | "ipdb> y\n" |
|
167 | "ipdb> y\n" | |
172 | ] |
|
168 | ] | |
173 | }, |
|
169 | }, | |
174 | { |
|
170 | { | |
175 | "output_type": "stream", |
|
171 | "output_type": "stream", | |
176 | "stream": "stdout", |
|
172 | "stream": "stdout", | |
177 | "text": [ |
|
173 | "text": [ | |
178 | "0\n" |
|
174 | "0\n" | |
179 | ] |
|
175 | ] | |
180 | }, |
|
176 | }, | |
181 | { |
|
177 | { | |
182 | "name": "stdout", |
|
|||
183 | "output_type": "stream", |
|
178 | "output_type": "stream", | |
184 | "stream": "stdout", |
|
179 | "stream": "stdout", | |
185 | "text": [ |
|
180 | "text": [ | |
186 | "ipdb> exit\n" |
|
181 | "ipdb> exit\n" | |
187 | ] |
|
182 | ] | |
188 | } |
|
183 | } | |
189 | ], |
|
184 | ], | |
190 | "prompt_number": 5 |
|
185 | "prompt_number": 5 | |
191 | } |
|
186 | } | |
192 | ], |
|
187 | ], | |
193 | "metadata": {} |
|
188 | "metadata": {} | |
194 | } |
|
189 | } | |
195 | ] |
|
190 | ] | |
196 | } No newline at end of file |
|
191 | } |
@@ -1,61 +1,61 b'' | |||||
1 | { |
|
1 | { | |
2 | "metadata": { |
|
2 | "metadata": { | |
3 | "name": "gilsleep" |
|
3 | "name": "gilsleep" | |
4 | }, |
|
4 | }, | |
5 | "nbformat": 3, |
|
5 | "nbformat": 3, | |
6 | "nbformat_minor": 0, |
|
6 | "nbformat_minor": 0, | |
7 | "worksheets": [ |
|
7 | "worksheets": [ | |
8 | { |
|
8 | { | |
9 | "cells": [ |
|
9 | "cells": [ | |
10 | { |
|
10 | { | |
11 | "cell_type": "markdown", |
|
11 | "cell_type": "markdown", | |
12 | "metadata": {}, |
|
12 | "metadata": {}, | |
13 | "source": [ |
|
13 | "source": [ | |
14 | "Holding the GIL for too long could disrupt the heartbeat due to non-copying sends.\n", |
|
14 | "Holding the GIL for too long could disrupt the heartbeat due to non-copying sends.\n", | |
15 | "\n", |
|
15 | "\n", | |
16 | "The following cell repeatedly calls a function that holds the GIL for five seconds.\n", |
|
16 | "The following cell repeatedly calls a function that holds the GIL for five seconds.\n", | |
17 | "\n", |
|
17 | "\n", | |
18 | "The heartbeat will fail after a few iterations prior to fixing Issue [#1260](https://github.com/ipython/ipython/issues/1260)." |
|
18 | "The heartbeat will fail after a few iterations prior to fixing Issue [#1260](https://github.com/ipython/ipython/issues/1260)." | |
19 | ] |
|
19 | ] | |
20 | }, |
|
20 | }, | |
21 | { |
|
21 | { | |
22 | "cell_type": "code", |
|
22 | "cell_type": "code", | |
23 | "collapsed": false, |
|
23 | "collapsed": false, | |
24 | "input": [ |
|
24 | "input": [ | |
25 | "import sys\n", |
|
25 | "import sys\n", | |
26 | "import time\n", |
|
26 | "import time\n", | |
27 | "\n", |
|
27 | "\n", | |
28 | "from cython import inline\n", |
|
28 | "from cython import inline\n", | |
29 | "\n", |
|
29 | "\n", | |
30 | "def gilsleep(t):\n", |
|
30 | "def gilsleep(t):\n", | |
31 | " \"\"\"gil-holding sleep with cython.inline\"\"\"\n", |
|
31 | " \"\"\"gil-holding sleep with cython.inline\"\"\"\n", | |
32 | " code = '\\n'.join([\n", |
|
32 | " code = '\\n'.join([\n", | |
33 | " 'from posix cimport unistd',\n", |
|
33 | " 'from posix cimport unistd',\n", | |
34 | " 'unistd.sleep(t)',\n", |
|
34 | " 'unistd.sleep(t)',\n", | |
35 | " ])\n", |
|
35 | " ])\n", | |
36 | " while True:\n", |
|
36 | " while True:\n", | |
37 | " inline(code, quiet=True, t=t)\n", |
|
37 | " inline(code, quiet=True, t=t)\n", | |
38 | " print time.time()\n", |
|
38 | " print time.time()\n", | |
39 | " sys.stdout.flush() # this is important\n", |
|
39 | " sys.stdout.flush() # this is important\n", | |
40 | "\n", |
|
40 | "\n", | |
41 | "gilsleep(5)" |
|
41 | "gilsleep(5)" | |
42 | ], |
|
42 | ], | |
43 | "language": "python", |
|
43 | "language": "python", | |
44 | "metadata": {}, |
|
44 | "metadata": {}, | |
45 | "outputs": [], |
|
45 | "outputs": [], | |
46 | "prompt_number": 1 |
|
46 | "prompt_number": 1 | |
47 | }, |
|
47 | }, | |
48 | { |
|
48 | { | |
49 | "cell_type": "code", |
|
49 | "cell_type": "code", | |
50 | "collapsed": true, |
|
50 | "collapsed": true, | |
51 | "input": [], |
|
51 | "input": [], | |
52 | "language": "python", |
|
52 | "language": "python", | |
53 | "metadata": {}, |
|
53 | "metadata": {}, | |
54 | "outputs": [], |
|
54 | "outputs": [], | |
55 |
"prompt_number": |
|
55 | "prompt_number": null | |
56 | } |
|
56 | } | |
57 | ], |
|
57 | ], | |
58 | "metadata": {} |
|
58 | "metadata": {} | |
59 | } |
|
59 | } | |
60 | ] |
|
60 | ] | |
61 | } No newline at end of file |
|
61 | } |
General Comments 0
You need to be logged in to leave comments.
Login now