Show More
@@ -112,31 +112,30 b' def _check_mp_mode(km, expected=False, stream="stdout"):' | |||||
112 | nt.assert_equal(eval(stdout.strip()), expected) |
|
112 | nt.assert_equal(eval(stdout.strip()), expected) | |
113 |
|
113 | |||
114 |
|
114 | |||
115 | @dec.parametric |
|
|||
116 | def test_simple_print(): |
|
115 | def test_simple_print(): | |
117 | """simple print statement in kernel""" |
|
116 | """simple print statement in kernel""" | |
118 | with new_kernel() as km: |
|
117 | with new_kernel() as km: | |
119 | iopub = km.sub_channel |
|
118 | iopub = km.sub_channel | |
120 | msg_id, content = execute(km=km, code="print ('hi')") |
|
119 | msg_id, content = execute(km=km, code="print ('hi')") | |
121 | stdout, stderr = assemble_output(iopub) |
|
120 | stdout, stderr = assemble_output(iopub) | |
122 |
|
|
121 | nt.assert_equal(stdout, 'hi\n') | |
123 |
|
|
122 | nt.assert_equal(stderr, '') | |
124 |
|
|
123 | _check_mp_mode(km, expected=False) | |
|
124 | print ('hello') | |||
125 |
|
125 | |||
126 |
|
126 | |||
127 | @dec.parametric |
|
|||
128 | def test_subprocess_print(): |
|
127 | def test_subprocess_print(): | |
129 | """printing from forked mp.Process""" |
|
128 | """printing from forked mp.Process""" | |
130 | with new_kernel() as km: |
|
129 | with new_kernel() as km: | |
131 | iopub = km.sub_channel |
|
130 | iopub = km.sub_channel | |
132 |
|
131 | |||
133 |
|
|
132 | _check_mp_mode(km, expected=False) | |
134 | flush_channels(km) |
|
133 | flush_channels(km) | |
135 | np = 5 |
|
134 | np = 5 | |
136 | code = '\n'.join([ |
|
135 | code = '\n'.join([ | |
137 | "import multiprocessing as mp", |
|
136 | "import multiprocessing as mp", | |
138 | "def f(x):", |
|
137 | "def f(x):", | |
139 |
" print |
|
138 | " print('hello',x)", | |
140 | "pool = [mp.Process(target=f,args=(i,)) for i in range(%i)]" % np, |
|
139 | "pool = [mp.Process(target=f,args=(i,)) for i in range(%i)]" % np, | |
141 | "for p in pool: p.start()", |
|
140 | "for p in pool: p.start()", | |
142 | "for p in pool: p.join()" |
|
141 | "for p in pool: p.join()" | |
@@ -148,15 +147,14 b' def test_subprocess_print():' | |||||
148 |
|
147 | |||
149 | msg_id, content = execute(km=km, code=code) |
|
148 | msg_id, content = execute(km=km, code=code) | |
150 | stdout, stderr = assemble_output(iopub) |
|
149 | stdout, stderr = assemble_output(iopub) | |
151 |
|
|
150 | nt.assert_equal(stdout.count("hello"), np, stdout) | |
152 | for n in range(np): |
|
151 | for n in range(np): | |
153 |
|
|
152 | nt.assert_equal(stdout.count(str(n)), 1, stdout) | |
154 |
|
|
153 | nt.assert_equal(stderr, '') | |
155 |
|
|
154 | _check_mp_mode(km, expected=True) | |
156 |
|
|
155 | _check_mp_mode(km, expected=False, stream="stderr") | |
157 |
|
156 | |||
158 |
|
157 | |||
159 | @dec.parametric |
|
|||
160 | def test_subprocess_noprint(): |
|
158 | def test_subprocess_noprint(): | |
161 | """mp.Process without print doesn't trigger iostream mp_mode""" |
|
159 | """mp.Process without print doesn't trigger iostream mp_mode""" | |
162 | with new_kernel() as km: |
|
160 | with new_kernel() as km: | |
@@ -174,13 +172,13 b' def test_subprocess_noprint():' | |||||
174 |
|
172 | |||
175 | msg_id, content = execute(km=km, code=code) |
|
173 | msg_id, content = execute(km=km, code=code) | |
176 | stdout, stderr = assemble_output(iopub) |
|
174 | stdout, stderr = assemble_output(iopub) | |
177 |
|
|
175 | nt.assert_equal(stdout, '') | |
178 |
|
|
176 | nt.assert_equal(stderr, '') | |
|
177 | ||||
|
178 | _check_mp_mode(km, expected=False) | |||
|
179 | _check_mp_mode(km, expected=False, stream="stderr") | |||
179 |
|
180 | |||
180 | yield _check_mp_mode(km, expected=False) |
|
|||
181 | yield _check_mp_mode(km, expected=False, stream="stderr") |
|
|||
182 |
|
181 | |||
183 | @dec.parametric |
|
|||
184 | def test_subprocess_error(): |
|
182 | def test_subprocess_error(): | |
185 | """error in mp.Process doesn't crash""" |
|
183 | """error in mp.Process doesn't crash""" | |
186 | with new_kernel() as km: |
|
184 | with new_kernel() as km: | |
@@ -197,9 +195,9 b' def test_subprocess_error():' | |||||
197 |
|
195 | |||
198 | msg_id, content = execute(km=km, code=code) |
|
196 | msg_id, content = execute(km=km, code=code) | |
199 | stdout, stderr = assemble_output(iopub) |
|
197 | stdout, stderr = assemble_output(iopub) | |
200 |
|
|
198 | nt.assert_equal(stdout, '') | |
201 | nt.assert_true("ZeroDivisionError" in stderr, stderr) |
|
199 | nt.assert_true("ZeroDivisionError" in stderr, stderr) | |
202 |
|
200 | |||
203 |
|
|
201 | _check_mp_mode(km, expected=False) | |
204 |
|
|
202 | _check_mp_mode(km, expected=True, stream="stderr") | |
205 |
|
203 |
General Comments 0
You need to be logged in to leave comments.
Login now