-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Make comm manager (mostly) independent of InteractiveShell #6540
Conversation
This makes it possible to use comms from wrapper kernels, without instantiating the full IPython shell machinery. The one remaining place where we need a reference to shell is to fire pre_execute and post_execute hooks (which are needed to get mpl figures right). This is a pure IPythonism, that it should be safe to ignore if shell is not set.
@@ -63,7 +62,7 @@ def _publish_msg(self, msg_type, data=None, metadata=None, **keys): | |||
self.session.send(self.iopub_socket, msg_type, | |||
content, | |||
metadata=json_clean(metadata), | |||
parent=self.shell.get_parent(), | |||
parent=self.kernel._parent_header, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely happy about using this private attribute - I suspect there should be a public API on Kernel to get the parent header.
Custom kernels would use this by instantiating |
Great! Am now checking this out... |
Hmm, I've missed a bit in |
@takluyver I see... |
@dsblank I've just rewritten that to use |
This now makes an architectural change for IPython: it's the kernel that has the comm manager, whereas previously it was the shell. |
This looks cleaner in that there isn't the need to call out to On Wed, Sep 24, 2014 at 8:50 PM, Thomas Kluyver notifications@github.com
|
You're welcome :) |
if self.shell is None or not hasattr(self.shell, 'kernel'): | ||
return | ||
return self.shell.kernel.session | ||
return self.kernel.session |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you still need to check if self.kernel is None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should never be reached if kernel is None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be during traitlet initialization. Setting a traitlet triggers its _default
method (I think in order to determine if _changed
should fire). So CommManager(session=foo, kernel=k)
can trigger this call with kernel=None
, depending on dictionary ordering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since kernel is a singleton, the default for .kernel
should retrieve the instance anyway. Though if people instantiate it by calling the class, that doesn't register the singleton instance. I guess I'll put in the safeguard...
I am happy with the current state of this if people want to review/merge it. |
Looks good. Merging soon is no objections. |
Thanks @takluyver ! |
Make comm manager (mostly) independent of InteractiveShell
Make comm manager (mostly) independent of InteractiveShell
This makes it possible to use comms from wrapper kernels, without instantiating the full IPython shell machinery.
The one remaining place where we need a reference to shell is to fire pre_execute and post_execute hooks (which are needed to get mpl figures right). This is a pure IPythonism, that it should be safe to ignore if shell is not set.
Ping @dsblank - you were asking about this in #6314.