Skip to content

Commit

Permalink
parallel magic: add -e to %px to also evaluate line in current kernel…
Browse files Browse the repository at this point in the history
…; fix buf in checking for list of None's
  • Loading branch information
dsblank committed Sep 12, 2014
1 parent 486dba5 commit 564b6f3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions jupyter_kernel/magics/parallel_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ def line_parallel(self, module_name, class_name, kernel_name="default", ids=None
'-k', '--kernel_name', action='store', default=None,
help='kernel name given to use for execution'
)
def line_px(self, expression, kernel_name=None):
@option(
'-e', '--evaluate', action='store_true', default=False,
help=('evaluate code in the current kernel, too. The current ' +
'kernel should be of the same language as the cluster.')
)
def line_px(self, expression, kernel_name=None, evaluate=False):
"""
%px EXPRESSION - send EXPRESSION to the cluster.
Expand All @@ -107,6 +112,8 @@ def line_px(self, expression, kernel_name=None):
kernel_name = self.kernel_name
self.retval = self.view["kernels['%s'].do_execute_direct(\"%s\")" % (
kernel_name, self._clean_code(expression))]
if evaluate:
self.code = expression

def _clean_code(self, expr):
return expr.strip().replace('"', '\\"').replace("\n", "\\n")
Expand Down Expand Up @@ -139,8 +146,12 @@ def cell_px(self, kernel_name=None, evaluate=False):
self.evaluate = evaluate

def post_process(self, retval):
if isinstance(self.retval, list) and not any(self.retval):
return None
try:
## any will crash on numpy arrays
if isinstance(self.retval, list) and not any(self.retval):
return None
except:
pass
return self.retval

def register_magics(kernel):
Expand Down

0 comments on commit 564b6f3

Please sign in to comment.