sharing a namespace across multiple ipython notebooks

ipython, jupyter-notebook

Solution

Unfortunately this no longer works, you get error message ipython.kernel replaced by ipython.parallel.

A less elegant way than above to alter this is to change IPython/frontend/html/notebook/kernelmanager.py around line 273 from

kernel_id = self.kernel_for_notebook(notebook_id)

to

kernel_id = None
for notebook_id in self._notebook_mapping:
    kernel_id = self._notebook_mapping[notebook_id]
    break

For Anaconda python, replace start_kernel in kernelmanager.py with

def start_kernel(self, kernel_id=None, path=None, **kwargs):
    global saved_kernel_id
    if saved_kernel_id:
        return saved_kernel_id
    if kernel_id is None:
        kwargs['extra_arguments'] = self.kernel_argv
        if path is not None:
            kwargs['cwd'] = self.cwd_for_path(path)
        kernel_id = super(MappingKernelManager, self).start_kernel(**kwargs)
        self.log.info("Kernel started: %s" % kernel_id)
        self.log.debug("Kernel args: %r" % kwargs)
        self.add_restart_callback(kernel_id,
            lambda : self._handle_kernel_died(kernel_id),
            'dead',
        )
    else:
        self._check_kernel_id(kernel_id)
        self.log.info("Using existing kernel: %s" % kernel_id)
    saved_kernel_id = kernel_id
    return kernel_id

and add

    saved_kernel_id = None

above

    class MappingKernelManager(MultiKernelManager):

True IPython gurus, please supply the correct fix. A lot of people using notebooks want the ability to share the kernel, it's natural, because one notebook quickly grows too big to work with a single complex application, so it is easier to be able to break down the application into multiple notebooks.

Also, gurus, while you're listening, it would be nice to have a collapse-expand feature as in Mathematica so you can only view the part of the notebook you care about and you can zoom out the rest.

Problem

I would like to work with several ipython notebooks at once sharing the same namespace. Is there currently (ipython-1.1.0) a way to do this? I tried creating different notebooks on the same ipython kernel, but the notebooks don't share a namespace. Also, I've been able to use a terminal console alongside a notebook on the same namespace using the answers in Using IPython console along side IPython notebook, but I couldn't find the notebook equivalent of the --existing argument. Thanks a lot

Original source