Finish up embed_kernel #1640

Merged
merged 13 commits into from Apr 23, 2012

Conversation

Projects
None yet
3 participants
Owner

minrk commented Apr 21, 2012

This is just a few more commits on top of PR #1357, addressing the pending review on that one.

Changes, per review in #1357:

  • fix inheritance of user_module/ns (IPKernelApp never has them)
  • remove unnecessarily specific extract_module_locals_above
  • super basic tests
  • note in docs
  • docstrings

Extra edit, to better match IPython.embed():

  • embed_kernel takes **kwargs to allow configuration of the kernel

scottt and others added some commits Jan 30, 2012

@scottt scottt add IPython.embed_kernel()
This patch adds IPython.embed_kernel() as a public API.
Embedding an IPython kernel in an application is useful when you want to
use IPython.embed() but don't have a terminal attached on stdin and stdout.

My use case is a modern gdb with Python API support
 #!/usr/bin/gdb --python
 import IPython; IPython.embed_kernel()
this way I get to use ipython to explore the GDB API without
the readline librarry in gdb and ipython fighting over the terminal settings.

A Google search revealed that other people were interetsted in this use
case as well:
http://mail.scipy.org/pipermail/ipython-dev/2011-July/007928.html
25e21eb
@scottt scottt zmq.ipkernel: don't call embed_kernel() in main() 8f53ec7
@scottt scottt zmq.Kernel: turn user_{module,ns} into traitlets a92b812
@scottt scottt embed_kernel: give a clear error message on pyzmq ImportError a96b676
@scottt scottt embed_kernel: fix pyzmq version requirement error message a2ec8bd
@scottt scottt embed_kernel: pass [] to IPKernelApp.initialize to prevent argv parsing
https://github.com/ipython/ipython/pull/1357/files#r400153
Stop embed_kernel() from parsing sys.argv since to support being called from
a environments with their own command line args.
75b852d
@scottt scottt embed_kernel: only import zmq when needed 087e9c3
@scottt scottt Move caller_module_and_locals() to IPython.util.frame 030fc46
@scottt scottt Refactor caller_module_locals() into extract_module_locals() a61f445
@minrk minrk add basic embed_kernel tests 940b5fb
@minrk minrk remove unnecessarily specific extract_module_locals_above d29d623
@minrk minrk adjust embed_kernel signature
* `**kwargs` are passed to KernelApp for config
* add docstring
* IPython.zmq.ipapp.embed_kernel is now fully functional
* allow re-entry to kernel
7b474d9
@minrk minrk add note about embed_kernel to embedding docs 43dabec
Owner

fperez commented Apr 23, 2012

This looks great, @minrk, thanks! Your new commits pretty much finish up the job. The only thing I can think of is that I remembered we have these two examples (both of which depend on this file of kernel embedding.

It would be great to update those examples to these cleaner APIs. But if you're swamped, I can do that in a separate PR, just let me know. In that case we'll merge this one and I'll do that later.

Owner

minrk commented Apr 23, 2012

Sure, I'll do that tomorrow.

-MinRK

On Apr 22, 2012, at 20:15, Fernando Perezreply@reply.github.com wrote:

This looks great, @minrk, thanks! Your new commits pretty much finish up the job. The only thing I can think of is that I remembered we have these two examples (both of which depend on this file of kernel embedding.

It would be great to update those examples to these cleaner APIs. But if you're swamped, I can do that in a separate PR, just let me know. In that case we'll merge this one and I'll do that later.


Reply to this email directly or view it on GitHub:
#1640 (comment)

Owner

fperez commented Apr 23, 2012

On Sun, Apr 22, 2012 at 11:04 PM, Min RK
reply@reply.github.com
wrote:

Sure, I'll do that tomorrow.

Awesome, thanks!

Owner

minrk commented Apr 23, 2012

Hm, those examples integrate a kernel, but don't seem to actually embed one (they aren't invoked into a specific namespace). I'm not sure how they would benefit from using embed_kernel.

Owner

fperez commented Apr 23, 2012

Right, but that's b/c when I first wrote them I had trouble making them a regular embedded example... Actually never mind: it's easier for me to clean these guys up once we merge this PR rather than asking you to read my mind :) Ignore those guys, and I'll clean them up as soon as I have a minute.

With that aside, this looks good to go! Anything in your mind that we should hold for?

Owner

minrk commented Apr 23, 2012

Okay, I'll let you look into those, then.

This seems good to me, then.

@fperez fperez added a commit that referenced this pull request Apr 23, 2012

@fperez fperez Merge pull request #1640 from minrk/embedkernel
Add IPython.embed_kernel() as a public API.

Embedding an IPython kernel in an application is useful when you want to use IPython.embed() but don't have a terminal attached on stdin and stdout.
14dcd99

@fperez fperez merged commit 14dcd99 into ipython:master Apr 23, 2012

Owner

fperez commented Apr 23, 2012

thanks everyone, this is great work! @scottt: we really appreciate your patience pushing this through multiple PRs. This particular feature is very important, so I'm thrilled to see it in.

@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014

@fperez fperez Merge pull request #1640 from minrk/embedkernel
Add IPython.embed_kernel() as a public API.

Embedding an IPython kernel in an application is useful when you want to use IPython.embed() but don't have a terminal attached on stdin and stdout.
254d4b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment