Thanks to visit codestin.com
Credit goes to github.com

Skip to content

IPEP 12: add KernelClient #3011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 70 commits into from
Apr 25, 2013
Merged

IPEP 12: add KernelClient #3011

merged 70 commits into from
Apr 25, 2013

Conversation

minrk
Copy link
Member

@minrk minrk commented Mar 10, 2013

This is the big first step in IPEP 12: splitting the two roles of KernelManager into two objects - exactly one KernelManager, which starts/stops/restarts kernels, and zero-to-many KernelClients, which perform actions via channels.

  • add KernelClient, split KernelManager
  • reorganize IPython.kernel module layout to reduce redundancy
  • update zmq console to new KM + KC API
  • update qt console to new KM + KC API
  • update existing tests
  • add new tests
  • expose shell_channel.method as KC.method
  • cleanup assumptions and boundaries among MultiKernelManager / MappingKernelManager
  • update inprocess cases to new API
  • add inprocess examples
  • add Control channel to get back clean kernel shutdown / restart
  • finish autorestart logic in notebook
  • hook up autorestart in qtconsole

I have not enabled autorestart in the plain terminal console, I am not sure that I should, since there is no background eventloop, unlike the qtconsole and notebook.

IPEP12-related changes that are not part of this PR:

  • base Channels should not be threads
  • ipython kernel entrypoint should operate via a KernelManager
  • ipengine should use KernelManagers

@ellisonbg
Copy link
Member

Great, I will try to have a look at this soon.

@minrk
Copy link
Member Author

minrk commented Mar 26, 2013

I think I will not reorganize the channels to not be threads in this PR - it seems a bit out of scope.

@minrk
Copy link
Member Author

minrk commented Mar 27, 2013

Looks like I'm almost there. The only thing remaining is to finish up the autorestart work started in the parent PR.

I am not confident in the in-process kernel - the test coverage is minimal, and there are zero use cases within IPython. I really don't like that we have something this complicated that is totally unused and almost totally untested.

@minrk
Copy link
Member Author

minrk commented Apr 6, 2013

I think this is ready for review

@ccordoba12
Copy link
Member

I would like to help here because I think this could simplify things a lot for us. How can I do it?

@minrk
Copy link
Member Author

minrk commented Apr 6, 2013

Mainly this just needs review, I think it's complete now.​

@ccordoba12
Copy link
Member

I meant help with testing :) Is there something expected to work differently with the new API? Some corner case that needs a little bit of extra help to test? If not, then just ignore me :)

@minrk
Copy link
Member Author

minrk commented Apr 6, 2013

Gotcha, thanks.

Most things work the same, with these changes:

  1. if you are starting a kernel, create a KernelManager
  2. if you want to use the kernel, create a KernelClient (this means that to connect to an already-running Kernel, you do not create a KernelManager)
  3. shell_channel.methods are all available as KernelClient.methods (this is just a proxy for convenience, the old way works as well)
  4. kernels can autorestart, rather than relying on user-input after heartbeat failures. To enable this behavior, create a KernelManager(...autorestart=True). autorestart is not the default behavior.

@@ -0,0 +1,127 @@
"""Abstract base classes for kernel client channels"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably name this channelsabc.py for consistency with other foo/fooabc naming convention.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

minrk added 19 commits April 23, 2013 21:47
required adding **kwarg passthrough in InteractiveShell parents
makes it harder to mistake a quick restart from real failure
generally not necessary, but sometimes the kernel connection can be dirty.
We have only seen this by starting a qtconsole via %qtconsole,
then killing the kernel, at which point the original notebook's connection
(at the zmq level) is never restored to the new kernel at the same endpoint.
It's weird, and probably a zmq bug, but a simple reconnect seems to solve it.
avoids lingering connections to zmq sockets across kernel restart
it wasn't actually necessary (proper fix in previous commit)
So that the qtconsole can notice that a kernel has restarted uncleanly
@ellisonbg
Copy link
Member

Testing restarts in qtconsole (no notebook):

I ran the qtconsole and tried killing the kernels using:

import sys
from ctypes import CDLL
# This will crash a Linux or Mac system; equivalent calls can be made on Windows
dll = 'dylib' if sys.platform == 'darwin' else 'so.6'
libc = CDLL("libc.%s" % dll) 
libc.time(-1)  # BOOM!!

I did this repeatedly and in different tabs. I observed the following tracebacks:

[IPythonQtConsoleApp] kernel restarted
Traceback (most recent call last):
  File "/Users/bgranger/Documents/Computing/IPython/code/ipython/IPython/frontend/qt/base_frontend_mixin.py", line 138, in _dispatch
    handler(msg)
  File "/Users/bgranger/Documents/Computing/IPython/code/ipython/IPython/frontend/qt/console/ipython_widget.py", line 179, in _handle_execute_reply
    super(IPythonWidget, self)._handle_execute_reply(msg)
  File "/Users/bgranger/Documents/Computing/IPython/code/ipython/IPython/frontend/qt/console/frontend_widget.py", line 423, in _handle_execute_reply
    self._request_info['execute'].pop(msg_id)
KeyError: u'387e4e3e-4386-4f06-94b9-6de3dd911f7d'
Traceback (most recent call last):
  File "/Users/bgranger/Documents/Computing/IPython/code/ipython/IPython/frontend/qt/console/mainwindow.py", line 241, in close_tab
    kernel_manager.shutdown_kernel()
NameError: global name 'kernel_manager' is not defined

I am trying to find reproducible steps to help debug this.

@ellisonbg
Copy link
Member

I am having trouble finding a good way to reproduce these errors, but the second one is a clear bug in the code. The kernel_manager variable is simply not defined in that scope of mainwindow.py.

@ellisonbg
Copy link
Member

Great work, merging!

ellisonbg added a commit that referenced this pull request Apr 25, 2013
@ellisonbg ellisonbg merged commit ce1ad53 into ipython:master Apr 25, 2013
@minrk minrk deleted the kernelclient branch March 31, 2014 23:36
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants