Skip to content
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

Merged
merged 3 commits into from
Oct 12, 2014

Conversation

takluyver
Copy link
Member

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.

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,
Copy link
Member Author

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.

@takluyver
Copy link
Member Author

Custom kernels would use this by instantiating CommManager(kernel=self), with no shell parameter.

@dsblank
Copy link
Contributor

dsblank commented Sep 24, 2014

Great! Am now checking this out...

@takluyver
Copy link
Member Author

Hmm, I've missed a bit in IPython.kernel.comm.comm.Comm.open() and .close() - the comm uses the shell to get a reference to the comm manager. I'll keep thinking about that.

@dsblank
Copy link
Contributor

dsblank commented Sep 25, 2014

@takluyver I see... comm.open() and comm.close() both call get_ipython() to get access to the CommManager. Those get_ipython() calls should probably be calls to self._shell_default(), but there should really be a self._comm_manager() which we could overload, right?

@takluyver
Copy link
Member Author

@dsblank I've just rewritten that to use self.kernel. When you instantiate CommManager, you will need to attach it to your Kernel subclass as kernel.comm_manager.

@takluyver
Copy link
Member Author

This now makes an architectural change for IPython: it's the kernel that has the comm manager, whereas previously it was the shell.

@dsblank
Copy link
Contributor

dsblank commented Sep 25, 2014

This looks cleaner in that there isn't the need to call out to
get_ipython(). I do see a few "get_ipython()s" sprinkled throughout the
codebase, but this looks like a good start to try working on widgets from
other Python-based languages. Thanks!

On Wed, Sep 24, 2014 at 8:50 PM, Thomas Kluyver notifications@github.com
wrote:

This now makes an architectural change for IPython: it's the kernel that
has the comm manager, whereas previously it was the shell.


Reply to this email directly or view it on GitHub
#6540 (comment).

@takluyver
Copy link
Member Author

You're welcome :)

if self.shell is None or not hasattr(self.shell, 'kernel'):
return
return self.shell.kernel.session
return self.kernel.session
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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...

@takluyver takluyver added this to the 3.0 milestone Oct 7, 2014
@takluyver
Copy link
Member Author

I am happy with the current state of this if people want to review/merge it.

@Carreau
Copy link
Member

Carreau commented Oct 9, 2014

Looks good. Merging soon is no objections.

@jdfreder
Copy link
Member

Thanks @takluyver !

jdfreder added a commit that referenced this pull request Oct 12, 2014
Make comm manager (mostly) independent of InteractiveShell
@jdfreder jdfreder merged commit ddc0593 into ipython:master Oct 12, 2014
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Make comm manager (mostly) independent of InteractiveShell
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.

None yet

6 participants