Split namespace on multiple ipython laptops

I would like to work with multiple ipython laptops that use the same namespace at the same time. Is there currently (ipython-1.1.0) a way to do this?

I tried creating different laptops on the same ipython core, but laptops do not use namespace. Also, I was able to use the terminal console next to the laptop in the same namespace using the answers in Using the IPython console with the IPython laptop , but I could not find the laptop equivalent for the existing argument.

Thank you so much

+7
ipython ipython-notebook
source share
2 answers

IPython Notebook does not have the equivalent of --existing . Laptops do not share cores. This is not a limitation of the laptop itself, it is just a design decision made in the code of the laptop server. For example, the server code can be changed so that all laptops use the same core. You can do this with a little monkeypatching in your IPython configuration. Start by creating a profile:

 $ ipython profile create singlekernel [ProfileCreate] Generating default config file: u'~/.ipython/profile_singlekernel/ipython_config.py' [ProfileCreate] Generating default config file: u'~/.ipython/profile_singlekernel/ipython_qtconsole_config.py' [ProfileCreate] Generating default config file: u'~/.ipython/profile_singlekernel/ipython_notebook_config.py' [ProfileCreate] Generating default config file: u'~/.ipython/profile_singlekernel/ipython_nbconvert_config.py' 

and edit $(ipython locate profile singlekernel)/ipython_notebook_config.py to contain:

 # Configuration file for ipython-notebook. c = get_config() import os import uuid from IPython.kernel.multikernelmanager import MultiKernelManager def start_kernel(self, **kwargs): """Minimal override of MKM.start_kernel that always returns the same kernel""" kernel_id = kwargs.pop('kernel_id', str(uuid.uuid4())) if self.km is None: self.km = self.kernel_manager_factory(connection_file=os.path.join( self.connection_dir, "kernel-%s.json" % kernel_id), parent=self, autorestart=True, log=self.log ) if not self.km.is_alive(): self.log.info("starting single kernel") self.km.start_kernel(**kwargs) else: self.log.info("reusing existing kernel") self._kernels[kernel_id] = self.km return kernel_id MultiKernelManager.km = None MultiKernelManager.start_kernel = start_kernel 

This simply redefines the kernel launch mechanism to start only one core and return it with each subsequent request, instead of starting a new one for each kernel identifier.

Now when you start the laptop server using

 ipython notebook --profile singlekernel 

all laptops in this session will share the same core.

+4
source share

Unfortunately this does not work anymore, you get the ipython.kernel error message replaced by ipython.parallel.

A less elegant way than the above is to change IPython / frontend / html / notebook / kernelmanager.py to 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 with 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 

higher

  class MappingKernelManager(MultiKernelManager): 

Real IPython gurus, please provide the correct fix. Many people who use laptops want to be able to share the kernel, which is natural because one laptop quickly gets too big to work with one complex application, so it’s easier to split the application into several laptops.

In addition, the guru, while you are listening, it would be nice to have the U-turn function, as in Mathematica, so that you can only view the part of the notebook that you care about, and you can reduce the rest.

+4
source share

All Articles