##// END OF EJS Templates
add %pxconfig --[no-]verbose
MinRK -
Show More
@@ -61,14 +61,22 b' def exec_args(f):'
61 args = [
61 args = [
62 magic_arguments.argument('-b', '--block', action="store_const",
62 magic_arguments.argument('-b', '--block', action="store_const",
63 const=True, dest='block',
63 const=True, dest='block',
64 help="use blocking (sync) execution"
64 help="use blocking (sync) execution",
65 ),
65 ),
66 magic_arguments.argument('-a', '--noblock', action="store_const",
66 magic_arguments.argument('-a', '--noblock', action="store_const",
67 const=False, dest='block',
67 const=False, dest='block',
68 help="use non-blocking (async) execution"
68 help="use non-blocking (async) execution",
69 ),
69 ),
70 magic_arguments.argument('-t', '--targets', type=str,
70 magic_arguments.argument('-t', '--targets', type=str,
71 help="specify the targets on which to execute"
71 help="specify the targets on which to execute",
72 ),
73 magic_arguments.argument('--verbose', action="store_const",
74 const=True, dest="set_verbose",
75 help="print a message at each execution",
76 ),
77 magic_arguments.argument('--no-verbose', action="store_const",
78 const=False, dest="set_verbose",
79 help="don't print any messages",
72 ),
80 ),
73 ]
81 ]
74 for a in args:
82 for a in args:
@@ -130,6 +138,8 b' class ParallelMagics(Magics):'
130 view = None
138 view = None
131 # last result cache for %pxresult
139 # last result cache for %pxresult
132 last_result = None
140 last_result = None
141 # verbose flag
142 verbose = False
133
143
134 def __init__(self, shell, view, suffix=''):
144 def __init__(self, shell, view, suffix=''):
135 self.view = view
145 self.view = view
@@ -171,6 +181,8 b' class ParallelMagics(Magics):'
171 self.view.targets = self._eval_target_str(args.targets)
181 self.view.targets = self._eval_target_str(args.targets)
172 if args.block is not None:
182 if args.block is not None:
173 self.view.block = args.block
183 self.view.block = args.block
184 if args.set_verbose is not None:
185 self.verbose = args.set_verbose
174
186
175 @magic_arguments.magic_arguments()
187 @magic_arguments.magic_arguments()
176 @output_args
188 @output_args
@@ -234,7 +246,8 b' class ParallelMagics(Magics):'
234 str_targets = str(targets[:4])[:-1] + ', ..., ' + str(targets[-4:])[1:]
246 str_targets = str(targets[:4])[:-1] + ', ..., ' + str(targets[-4:])[1:]
235 else:
247 else:
236 str_targets = str(targets)
248 str_targets = str(targets)
237 print base + " execution on engine(s): %s" % str_targets
249 if self.verbose:
250 print base + " execution on engine(s): %s" % str_targets
238
251
239 result = self.view.execute(cell, silent=False, block=False)
252 result = self.view.execute(cell, silent=False, block=False)
240 self.last_result = result
253 self.last_result = result
@@ -88,7 +88,7 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
88
88
89 for block in (True, False):
89 for block in (True, False):
90 v.block = block
90 v.block = block
91
91 ip.magic("pxconfig --verbose")
92 with capture_output() as io:
92 with capture_output() as io:
93 ip.run_cell_magic("px", "", "1")
93 ip.run_cell_magic("px", "", "1")
94 if block:
94 if block:
@@ -117,7 +117,7 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
117 ip.run_cell_magic('px', '--group-outputs=engine', 'generate_output()')
117 ip.run_cell_magic('px', '--group-outputs=engine', 'generate_output()')
118
118
119 self.assertFalse('\n\n' in io.stdout)
119 self.assertFalse('\n\n' in io.stdout)
120 lines = io.stdout.splitlines()[1:]
120 lines = io.stdout.splitlines()
121 expected = [
121 expected = [
122 r'\[stdout:\d+\]',
122 r'\[stdout:\d+\]',
123 'stdout',
123 'stdout',
@@ -151,7 +151,7 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
151 ip.run_cell_magic('px', '--group-outputs=order', 'generate_output()')
151 ip.run_cell_magic('px', '--group-outputs=order', 'generate_output()')
152
152
153 self.assertFalse('\n\n' in io.stdout)
153 self.assertFalse('\n\n' in io.stdout)
154 lines = io.stdout.splitlines()[1:]
154 lines = io.stdout.splitlines()
155 expected = []
155 expected = []
156 expected.extend([
156 expected.extend([
157 r'\[stdout:\d+\]',
157 r'\[stdout:\d+\]',
@@ -192,7 +192,7 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
192 ip.run_cell_magic('px', '--group-outputs=type', 'generate_output()')
192 ip.run_cell_magic('px', '--group-outputs=type', 'generate_output()')
193
193
194 self.assertFalse('\n\n' in io.stdout)
194 self.assertFalse('\n\n' in io.stdout)
195 lines = io.stdout.splitlines()[1:]
195 lines = io.stdout.splitlines()
196
196
197 expected = []
197 expected = []
198 expected.extend([
198 expected.extend([
@@ -229,6 +229,7 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
229 self.assertEquals(v['a'], [5])
229 self.assertEquals(v['a'], [5])
230 ip.magic('px a=10')
230 ip.magic('px a=10')
231 self.assertEquals(v['a'], [10])
231 self.assertEquals(v['a'], [10])
232 ip.magic('pxconfig --verbose')
232 with capture_output() as io:
233 with capture_output() as io:
233 ar = ip.magic('px print (a)')
234 ar = ip.magic('px print (a)')
234 self.assertTrue(isinstance(ar, AsyncResult))
235 self.assertTrue(isinstance(ar, AsyncResult))
@@ -354,6 +355,7 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
354 rc = self.client
355 rc = self.client
355 view = rc.activate(rc.ids)
356 view = rc.activate(rc.ids)
356 self.assertEquals(view.targets, rc.ids)
357 self.assertEquals(view.targets, rc.ids)
358 ip.magic('pxconfig --verbose')
357 for cell in ("pass", "1/0"):
359 for cell in ("pass", "1/0"):
358 with capture_output() as io:
360 with capture_output() as io:
359 try:
361 try:
@@ -371,6 +373,7 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
371 view = rc.activate(rc.ids)
373 view = rc.activate(rc.ids)
372 view.block = False
374 view.block = False
373 self.assertEquals(view.targets, rc.ids)
375 self.assertEquals(view.targets, rc.ids)
376 ip.magic('pxconfig --verbose')
374 for cell in ("pass", "1/0"):
377 for cell in ("pass", "1/0"):
375 with capture_output() as io:
378 with capture_output() as io:
376 try:
379 try:
General Comments 0
You need to be logged in to leave comments. Login now