[IPython-dev] Connecting notebook to existing kernel

Madhusudan C.S madhusudancs at gmail.com
Mon Jan 2 02:28:57 EST 2012

Hello everyone,
   I have sent a new pull request for this issue which is at [0].
I have explained most of the details corresponding to the
pull request in the description there. This patch enables us
to connect a new notebook to an existing kernel, irrespective
of what type of kernel it is.

Before I go further into the details, my apologies for directly
sending in a pull request without discussing any design or
details of this thing with you guys. It was more of an adhoc
thing which arose from my frustration of not being able to
do this. This is just some code dump that I have put yesterday
night since I had a compelling need to get this working before
going to sleep :P

So for now this implemented by adding a new GET RequestHandlers
for the /kernels/<kernel_id> which has been modified to look for
either for Security key-like UUID4 pattern kernel ID or the
kernel-<PID>.json pattern file name. Upon supplying the latter
it calls the start_kernel method of the Notebook's MappingKernelManager
class with the connection_file argument and the MultiKernelManager
which is a super class of the MappingKernelManager has the
start_kernel method which looks for the connection_file if supplied
and tries to open that kernel.

On the UI side, an additional dialog is plugin to the "New" button.
On clicking the "New" button opens a dialog with the optional
text field labeled "kernel". One can either supply the kernel
file in which case the URL /kernels/<connection_file> is opened.
This opens a new notebook with the existing kernel. If the kernel
text field is left blank and "New" button is clicked a new notebook
will be opened as we have it now. A fresh notebook with a new

The implementation on the backend is a bit messy. But this is
because of the way the KernelManger and the NotebookApp
is implemented itself. I noticed that both qtconsole and the
terminal console both inherit from
IPython.frontend.consoleapp.IPythonConsoleApp. This makes
a lot of things like what I am trying to do much simpler because
all these stuff are already abstracted into that class. I am
not sure why that mixin was not used for the notebook application.
Also, I don't know why, when I execute commands which
access variables from other kernels I get the error like at [1]
printed on the console where I started the notebook. I don't
know what it means since I don't see that happening for
both qtconsole or the terminal console.

What do you guys think about it?

[0] https://github.com/ipython/ipython/pull/1220
[1] http://paste.pocoo.org/show/528733/

Thanks and regards,

Blogs at: www.madhusudancs.info
My Online Identity: madhusudancs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20120102/c017a502/attachment.html>

More information about the IPython-dev mailing list