From a8345ae5695df4235beb716a01d928e501c71337 2014-06-26 20:21:27 From: Julia Evans Date: 2014-06-26 20:21:27 Subject: [PATCH] Move kernel starting / stopping into preprocess() --- diff --git a/IPython/nbconvert/preprocessors/execute.py b/IPython/nbconvert/preprocessors/execute.py index a06373b..ad632da 100644 --- a/IPython/nbconvert/preprocessors/execute.py +++ b/IPython/nbconvert/preprocessors/execute.py @@ -24,15 +24,16 @@ class ExecutePreprocessor(Preprocessor): """ Executes all the cells in a notebook """ - def __init__(self, *args, **kwargs): + def __init__(self, extra_arguments=[], **kwargs): """ Start an kernel to run the Python code """ - super(ExecutePreprocessor, self).__init__(*args, **kwargs) + super(ExecutePreprocessor, self).__init__(**kwargs) + self.extra_arguments = [] + + def preprocess(self, nb, resources): self.km = KernelManager() - # run %pylab inline, because some notebooks assume this - # even though they shouldn't - self.km.start_kernel(extra_arguments=['--pylab=inline'], stderr=open(os.devnull, 'w')) + self.km.start_kernel(extra_arguments=self.extra_arguments, stderr=open(os.devnull, 'w')) self.kc = self.km.client() self.kc.start_channels() self.iopub = self.kc.iopub_channel @@ -41,6 +42,12 @@ class ExecutePreprocessor(Preprocessor): self.shell.execute("pass") self.shell.get_msg() + + create_client() + nb, resources = super(ExecutePreprocessor, self).preprocess(nb, resources) + shutdown_client() + return nb, resources + def preprocess_cell(self, cell, resources, cell_index): """ Apply a transformation on each code cell. See base.py for details.