##// END OF EJS Templates
add test for raising error in forked process
MinRK -
Show More
@@ -107,7 +107,7 b' def assemble_output(iopub):'
107 def _check_mp_mode(km, expected=False, stream="stdout"):
107 def _check_mp_mode(km, expected=False, stream="stdout"):
108 execute(km=km, code="import sys")
108 execute(km=km, code="import sys")
109 flush_channels(km)
109 flush_channels(km)
110 msg_id, content = execute(km=km, code="print (sys.stdout._check_mp_mode())")
110 msg_id, content = execute(km=km, code="print (sys.%s._check_mp_mode())" % stream)
111 stdout, stderr = assemble_output(km.sub_channel)
111 stdout, stderr = assemble_output(km.sub_channel)
112 nt.assert_equal(eval(stdout.strip()), expected)
112 nt.assert_equal(eval(stdout.strip()), expected)
113
113
@@ -117,7 +117,6 b' def test_simple_print():'
117 """simple print statement in kernel"""
117 """simple print statement in kernel"""
118 with new_kernel() as km:
118 with new_kernel() as km:
119 iopub = km.sub_channel
119 iopub = km.sub_channel
120
121 msg_id, content = execute(km=km, code="print ('hi')")
120 msg_id, content = execute(km=km, code="print ('hi')")
122 stdout, stderr = assemble_output(iopub)
121 stdout, stderr = assemble_output(iopub)
123 yield nt.assert_equal(stdout, 'hi\n')
122 yield nt.assert_equal(stdout, 'hi\n')
@@ -154,7 +153,7 b' def test_subprocess_print():'
154 yield nt.assert_equal(stdout.count(str(n)), 1, stdout)
153 yield nt.assert_equal(stdout.count(str(n)), 1, stdout)
155 yield nt.assert_equal(stderr, '')
154 yield nt.assert_equal(stderr, '')
156 yield _check_mp_mode(km, expected=True)
155 yield _check_mp_mode(km, expected=True)
157 yield _check_mp_mode(km, expected=True, stream="stderr")
156 yield _check_mp_mode(km, expected=False, stream="stderr")
158
157
159
158
160 @dec.parametric
159 @dec.parametric
@@ -181,3 +180,26 b' def test_subprocess_noprint():'
181 yield _check_mp_mode(km, expected=False)
180 yield _check_mp_mode(km, expected=False)
182 yield _check_mp_mode(km, expected=False, stream="stderr")
181 yield _check_mp_mode(km, expected=False, stream="stderr")
183
182
183 @dec.parametric
184 def test_subprocess_error():
185 """error in mp.Process doesn't crash"""
186 with new_kernel() as km:
187 iopub = km.sub_channel
188
189 code = '\n'.join([
190 "import multiprocessing as mp",
191 "def f():",
192 " return 1/0",
193 "p = mp.Process(target=f)",
194 "p.start()",
195 "p.join()",
196 ])
197
198 msg_id, content = execute(km=km, code=code)
199 stdout, stderr = assemble_output(iopub)
200 yield nt.assert_equal(stdout, '')
201 nt.assert_true("ZeroDivisionError" in stderr, stderr)
202
203 yield _check_mp_mode(km, expected=False)
204 yield _check_mp_mode(km, expected=True, stream="stderr")
205
General Comments 0
You need to be logged in to leave comments. Login now