IPython notebook: define a dummy cell magic that simply runs the cell as usual -
how can define simple cell magic executes cell if %%mymagic
wasn't there?
the context using wonderful ipython parallel framework. in places, use defined %%px
magic. we'd run same notebook without cluster (local only). in case, %%px
isn't defined , have comment out. instead, in case i'd redefine %%px
that:
%%px
: no-op.%%px --local
: runs cell, no other side-effect.
alternatively, %%px
(with --local
or not) run cell, if that's simpler.
another approach create ipyparallel client fake one, i.e. 0 nodes (but still operate correctly, e.g. regard %%px --local
). question.
things i've tried:
%alias_magic px time
(after all, don't care if cell timed). unfortunately,%%time
doesn't take arguments , chokes on--local
.define own "no-op" magic:
if use_client: pass else: # temporarily define %%px cell magic ipython import get_ipython def px(line, cell): """do nothing""" pass get_ipython().register_magic_function(px, 'cell')
but succeeds little @ doing really nothing (i.e. cells not executed).
look ipython/core/magics/execution.py see if there hook reuse (something execute cell). haven't found, perhaps haven't looked hard enough.
any other idea?
i think relevant command is
self.shell.run_cell(cell)
Comments
Post a Comment