Skip to content

Commit 0ab27d5

Browse files
committed
Update bg example with better structure.
1 parent 3ad2a30 commit 0ab27d5

File tree

1 file changed

+92
-42
lines changed

1 file changed

+92
-42
lines changed

notebooks/BackgroundJobs.ipynb

Lines changed: 92 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"source": [
5656
"Now, we can create a job manager (called simply `jobs`) and use it to submit new jobs.\n",
5757
"\n",
58-
"Run the cell below, it will show when the jobs start and you can keep working:"
58+
"Run the cell below, it will show when the jobs start. Wait a few seconds until you see the 'all done' completion message:"
5959
]
6060
},
6161
{
@@ -67,12 +67,7 @@
6767
"# Start a few jobs, the first one will have ID # 0\n",
6868
"jobs.new(sleepfunc, 4)\n",
6969
"jobs.new(sleepfunc, kw={'reps':2})\n",
70-
"jobs.new('printfunc(1,3)')\n",
71-
"\n",
72-
"# This makes a couple of jobs which will die. Let's keep a reference to\n",
73-
"# them for easier traceback reporting later\n",
74-
"diejob1 = jobs.new(diefunc, 1)\n",
75-
"diejob2 = jobs.new(diefunc, 2)"
70+
"jobs.new('printfunc(1,3)')"
7671
],
7772
"language": "python",
7873
"metadata": {},
@@ -83,13 +78,46 @@
8378
"text": [
8479
"Starting job # 0 in a separate thread.\n",
8580
"Starting job # 2 in a separate thread.\n",
86-
"Starting job # 3 in a separate thread.\n",
87-
"Starting job # 4 in a separate thread.\n",
88-
"Starting job # 5 in a separate thread.\n"
81+
"Starting job # 3 in a separate thread.\n"
82+
]
83+
},
84+
{
85+
"output_type": "pyout",
86+
"prompt_number": 10,
87+
"text": [
88+
"<BackgroundJob #3: printfunc(1,3)>"
89+
]
90+
},
91+
{
92+
"output_type": "stream",
93+
"stream": "stdout",
94+
"text": [
95+
"In the background... 0\n"
96+
]
97+
},
98+
{
99+
"output_type": "stream",
100+
"stream": "stdout",
101+
"text": [
102+
"In the background... 1\n"
103+
]
104+
},
105+
{
106+
"output_type": "stream",
107+
"stream": "stdout",
108+
"text": [
109+
"In the background... 2\n"
110+
]
111+
},
112+
{
113+
"output_type": "stream",
114+
"stream": "stdout",
115+
"text": [
116+
"All done!\n"
89117
]
90118
}
91119
],
92-
"prompt_number": 7
120+
"prompt_number": 10
93121
},
94122
{
95123
"cell_type": "markdown",
@@ -111,30 +139,15 @@
111139
"output_type": "stream",
112140
"stream": "stdout",
113141
"text": [
114-
"In the background... 0\n",
115-
"In the background... 1\n",
116-
"In the background... 2\n",
117-
"All done!\n",
118-
"Completed jobs:"
119-
]
120-
},
121-
{
122-
"output_type": "stream",
123-
"stream": "stdout",
124-
"text": [
125-
"\n",
126-
"0 : <function sleepfunc at 0x2ef9230>\n",
127-
"2 : <function sleepfunc at 0x2ef9230>\n",
142+
"Completed jobs:\n",
143+
"0 : <function sleepfunc at 0x314f848>\n",
144+
"2 : <function sleepfunc at 0x314f848>\n",
128145
"3 : printfunc(1,3)\n",
129-
"\n",
130-
"Dead jobs:\n",
131-
"4 : <function diefunc at 0x2ef91b8>\n",
132-
"5 : <function diefunc at 0x2ef91b8>\n",
133146
"\n"
134147
]
135148
}
136149
],
137-
"prompt_number": 9
150+
"prompt_number": 11
138151
},
139152
{
140153
"cell_type": "markdown",
@@ -153,14 +166,51 @@
153166
"metadata": {},
154167
"outputs": [
155168
{
156-
"metadata": {},
157169
"output_type": "pyout",
158-
"prompt_number": 13,
170+
"prompt_number": 12,
159171
"text": [
160172
"{'args': (), 'interval': 4, 'kwargs': {}}"
161173
]
162174
}
163175
],
176+
"prompt_number": 12
177+
},
178+
{
179+
"cell_type": "heading",
180+
"level": 2,
181+
"metadata": {},
182+
"source": [
183+
"Errors and tracebacks"
184+
]
185+
},
186+
{
187+
"cell_type": "markdown",
188+
"metadata": {},
189+
"source": [
190+
"The jobs manager tries to help you with debugging:"
191+
]
192+
},
193+
{
194+
"cell_type": "code",
195+
"collapsed": false,
196+
"input": [
197+
"# This makes a couple of jobs which will die. Let's keep a reference to\n",
198+
"# them for easier traceback reporting later\n",
199+
"diejob1 = jobs.new(diefunc, 1)\n",
200+
"diejob2 = jobs.new(diefunc, 2)"
201+
],
202+
"language": "python",
203+
"metadata": {},
204+
"outputs": [
205+
{
206+
"output_type": "stream",
207+
"stream": "stdout",
208+
"text": [
209+
"Starting job # 4 in a separate thread.\n",
210+
"Starting job # 5 in a separate thread.\n"
211+
]
212+
}
213+
],
164214
"prompt_number": 13
165215
},
166216
{
@@ -189,7 +239,7 @@
189239
"Status of diejob1: Dead (Exception), call jobs.traceback() for details\n",
190240
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n",
191241
"\u001b[1;31mException\u001b[0m Traceback (most recent call last)\n",
192-
"\u001b[1;32m/home/fperez/usr/lib/python2.7/site-packages/IPython/lib/backgroundjobs.pyc\u001b[0m in \u001b[0;36mcall\u001b[1;34m(self)\u001b[0m\n",
242+
"\u001b[1;32m/home/fperez/usr/opt/virtualenv/ipython-0.13.2/lib/python2.7/site-packages/IPython/lib/backgroundjobs.pyc\u001b[0m in \u001b[0;36mcall\u001b[1;34m(self)\u001b[0m\n",
193243
"\u001b[0;32m 482\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
194244
"\u001b[0;32m 483\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mcall\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
195245
"\u001b[1;32m--> 484\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
@@ -205,7 +255,7 @@
205255
]
206256
}
207257
],
208-
"prompt_number": 15
258+
"prompt_number": 14
209259
},
210260
{
211261
"cell_type": "markdown",
@@ -227,10 +277,10 @@
227277
"output_type": "stream",
228278
"stream": "stdout",
229279
"text": [
230-
"Traceback for: <BackgroundJob #4: <function diefunc at 0x2ef91b8>>\n",
280+
"Traceback for: <BackgroundJob #4: <function diefunc at 0x314f668>>\n",
231281
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n",
232282
"\u001b[1;31mException\u001b[0m Traceback (most recent call last)\n",
233-
"\u001b[1;32m/home/fperez/usr/lib/python2.7/site-packages/IPython/lib/backgroundjobs.pyc\u001b[0m in \u001b[0;36mcall\u001b[1;34m(self)\u001b[0m\n",
283+
"\u001b[1;32m/home/fperez/usr/opt/virtualenv/ipython-0.13.2/lib/python2.7/site-packages/IPython/lib/backgroundjobs.pyc\u001b[0m in \u001b[0;36mcall\u001b[1;34m(self)\u001b[0m\n",
234284
"\u001b[0;32m 482\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
235285
"\u001b[0;32m 483\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mcall\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
236286
"\u001b[1;32m--> 484\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
@@ -244,10 +294,10 @@
244294
"\n",
245295
"\u001b[1;31mException\u001b[0m: Dead job with interval 1\n",
246296
"\n",
247-
"Traceback for: <BackgroundJob #5: <function diefunc at 0x2ef91b8>>\n",
297+
"Traceback for: <BackgroundJob #5: <function diefunc at 0x314f668>>\n",
248298
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n",
249299
"\u001b[1;31mException\u001b[0m Traceback (most recent call last)\n",
250-
"\u001b[1;32m/home/fperez/usr/lib/python2.7/site-packages/IPython/lib/backgroundjobs.pyc\u001b[0m in \u001b[0;36mcall\u001b[1;34m(self)\u001b[0m\n",
300+
"\u001b[1;32m/home/fperez/usr/opt/virtualenv/ipython-0.13.2/lib/python2.7/site-packages/IPython/lib/backgroundjobs.pyc\u001b[0m in \u001b[0;36mcall\u001b[1;34m(self)\u001b[0m\n",
251301
"\u001b[0;32m 482\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
252302
"\u001b[0;32m 483\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mcall\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
253303
"\u001b[1;32m--> 484\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
@@ -264,7 +314,7 @@
264314
]
265315
}
266316
],
267-
"prompt_number": 16
317+
"prompt_number": 15
268318
},
269319
{
270320
"cell_type": "markdown",
@@ -291,7 +341,7 @@
291341
]
292342
}
293343
],
294-
"prompt_number": 17
344+
"prompt_number": 16
295345
},
296346
{
297347
"cell_type": "markdown",
@@ -309,7 +359,7 @@
309359
"language": "python",
310360
"metadata": {},
311361
"outputs": [],
312-
"prompt_number": 18
362+
"prompt_number": 17
313363
},
314364
{
315365
"cell_type": "markdown",
@@ -336,7 +386,7 @@
336386
]
337387
}
338388
],
339-
"prompt_number": 21
389+
"prompt_number": 18
340390
},
341391
{
342392
"cell_type": "markdown",

0 commit comments

Comments
 (0)