Getting output of jupyter_client execution

516 views
Skip to first unread message

saso...@colorado.edu

unread,
Feb 22, 2016, 2:35:56 PM2/22/16
to Project Jupyter
Hi,
I am trying to use the Jupyter_client API to run some code on a kernel. I am able to execute the code, but am not able to view the execution output. 
So far, I have tried the following

import jupyter_client
a = jupyter_client.KernelManager()
a.kernel_name = "python3"
a.start_kernel()
p = a.client()
m = p.execute("print('Hello, World')")

I tried using p.get_shell_msg(m) as suggested by the documentation, but I just got a JSON object, which didn't have the output. Am I missing something here?

Thanks,
Saurabh

Jan Schulz

unread,
Feb 22, 2016, 2:45:08 PM2/22/16
to jup...@googlegroups.com
Hi,

knitpy used this infrastructure to run code, so this might help:
https://github.com/JanSchulz/knitpy/blob/master/knitpy/knitpy.py#L458

Best,

Jan
--
Jan Schulz
mail: ja...@gmx.net
> --
> 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/5a459adf-a8d9-452d-a293-571b4657cf82%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

saso...@colorado.edu

unread,
Feb 22, 2016, 2:54:41 PM2/22/16
to Project Jupyter
Thanks for the reply Jan. I will look through the code and see how to get it working.

I have a general question. So if I try to run code using jupyter_client, am I running against a running instance of Jupyter, or am I starting an instance everytime I need to run code?

Regards,
Saurabh

Jan Schulz

unread,
Feb 22, 2016, 3:04:26 PM2/22/16
to jup...@googlegroups.com
Hi,

On 22 February 2016 at 20:54, <saso...@colorado.edu> wrote:
> I have a general question. So if I try to run code using jupyter_client, am
> I running against a running instance of Jupyter, or am I starting an
> instance everytime I need to run code?

You run it on a kernel which you started (-> `a.start_kernel()`), so
as long as that kernel is alive, you can run code on it (and the
previous defined variables/functions) are available.

Best,

Jan
--
Jan Schulz
mail: ja...@gmx.net
web: http://www.katzien.de

saso...@colorado.edu

unread,
Feb 22, 2016, 4:48:15 PM2/22/16
to Project Jupyter
Hi,
Thanks for the reply. 
I tried using pieces of the code, and see that my code gets stuck on 
msg = kernel.get_iopub_msg()

Is this normal?

Thanks,

Regards,
Saurabh

MinRK

unread,
Feb 23, 2016, 3:46:30 AM2/23/16
to jup...@googlegroups.com
On Mon, Feb 22, 2016 at 10:48 PM, <saso...@colorado.edu> wrote:
Hi,
Thanks for the reply. 
I tried using pieces of the code, and see that my code gets stuck on 
msg = kernel.get_iopub_msg()

You will want to call `client.start_channels()` after creating it, to establish the zmq connections.
 

Is this normal?

Thanks,

Regards,
Saurabh

On Monday, February 22, 2016 at 1:04:26 PM UTC-7, Jan Schulz wrote:
Hi,

On 22 February 2016 at 20:54,  <saso...@colorado.edu> wrote:
> I have a general question. So if I try to run code using jupyter_client, am
> I running against a running instance of Jupyter, or am I starting an
> instance everytime I need to run code?

You run it on a kernel which you started (-> `a.start_kernel()`), so
as long as that kernel is alive, you can run code on it (and the
previous defined variables/functions) are available.

Best,

Jan
--
Jan Schulz
mail: ja...@gmx.net
web: http://www.katzien.de

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

Jeff Zhang

unread,
Jul 1, 2017, 9:55:11 PM7/1/17
to Project Jupyter
I have the same issue that I could not get the output, does anyone have solution or sample code for that ? Thanks



在 2016年2月23日星期二 UTC+8下午4:46:30,Min RK写道:

MinRK

unread,
Jul 19, 2017, 10:57:16 AM7/19/17
to Project Jupyter

Here’s a script that runs some code with execute_interactive and captures various outputs.

-Min


To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.

Ariel Balter

unread,
Mar 21, 2018, 10:57:01 PM3/21/18
to Project Jupyter
Here is a simple jupyter_client wrapper for playing around:

 

matthias...@gmail.com

unread,
May 17, 2018, 6:17:19 AM5/17/18
to Project Jupyter
and here another demonstration in a notebook ...

Reply all
Reply to author
Forward
0 new messages