command line ipython kernel incantation / API?

52 views
Skip to first unread message

John Kitchin

unread,
Jun 6, 2017, 12:31:14 AM6/6/17
to Project Jupyter
Hi,

I was wondering if there is a command to start an ipython kernel that you can communicate with through http requests. I want to communicate with the kernel through emacs to execute  code blocks, inspect things, get completion targets, and to interrupt the kernel.  I haven't found any specific documentation that suggests this exists though.

I am familiar with the EIN project, but it does not seem to work for me. I also know of the ob-ipython project. I currently use that, but it has its own python driver to create a web server attached to a kernel. It does not support completion or interruption though, and it isn't obvious how to extend it.

Thanks!

Matthias Bussonnier

unread,
Jun 6, 2017, 1:42:10 AM6/6/17
to jup...@googlegroups.com
Hi John,

The (best?) place to start is Jupyter Client docs [1], if you want to
communicate with a pure kernel you'll have to use ZMQ – not much
harder than HTTP[2], it's basically sockets on steroids –. and you
want to manually use `python -m ipykernel <connection file>` to start
a python kernel. The connection file give you infomations on how to
bind/connect ZMQ ports. The "Making a kernel" part is the most
complete (as that's what usually people are interested in), and we
should improve the "making a client" part (maybe with your help ?).
Regardless bug report welcome, and despite the jupyter_client
implementation being in Python, any example in documentation in other
languages welcome.

Hope that helps get you started.

Cheers
--
M
[1] http://jupyter-client.readthedocs.io/en/latest/
[2] the "Http" communication with kernels is actually websoket, and
the `jupyter notebook`application is a websocket<->ZMQ bridge.
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jupyter+u...@googlegroups.com.
> To post to this group, send email to jup...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/fc7035bb-e5f1-43cc-ae05-47ce64243907%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

John Kitchin

unread,
Jun 8, 2017, 6:33:16 PM6/8/17
to Project Jupyter
Thanks for the pointers. I will take a look at these. If I get anything working, I would be happy to share it.

John Kitchin

unread,
Jun 8, 2017, 7:06:50 PM6/8/17
to Project Jupyter
I am trying something like this:

#+BEGIN_SRC python :results output org drawer
import jupyter_client as client
find_connection_file = client.find_connection_file

cf = find_connection_file('test')
c = client.BlockingKernelClient(connection_file=cf)
c.load_connection_file()
c.start_channels()

msgid = c.execute('a=9')
print(msgid)
#+END_SRC

#+RESULTS:
:RESULTS:
df3b62be-dd12-4ebe-8f93-0a6045dc632d
:END:

It seems that the a=9 code was executed, but I can't figure out how to get results back from the kernel. I expected I would get an execute_reply back, but I got a msg id instead. Am I supposed to use that in another call to get the reply or something?


On Monday, June 5, 2017 at 11:42:10 PM UTC-6, Matthias Bussonnier wrote:

Roland Weber

unread,
Jun 9, 2017, 2:08:07 AM6/9/17
to Project Jupyter
Hello John,

if you get a message ID instead of an actual reply, then you didn't specify to wait for the reply:
I'm not familiar with the API, but this might work:

  replymsg = c.execute('a=9', reply=True)


hope that helps,
  Roland

John Kitchin

unread,
Jun 9, 2017, 6:27:53 AM6/9/17
to Project Jupyter
Thanks. That doesn't seem to be allowed in the version of jupyter I have (it looks like I have protocol 5.0). 
Reply all
Reply to author
Forward
0 new messages