Execute code on a remote kernel using HTTP with kernel_gateway

170 views
Skip to first unread message

Andrew C

unread,
Oct 6, 2017, 3:33:15 PM10/6/17
to Project Jupyter
I want to set up a server with kernel_gateway that has some different kernels on it. The goal is to send some code to the server via HTTP, and have one of the kernels execute the code and send a response back with the result of the code being executed (it will onnly execute functions and so it will always have a return value). Is there an API call I can make to send code to kernel_gateway and have the kernel execute the code?

Luciano Resende

unread,
Oct 6, 2017, 9:56:28 PM10/6/17
to jup...@googlegroups.com
On Fri, Oct 6, 2017 at 12:33 PM, Andrew C <arc...@umich.edu> wrote:
I want to set up a server with kernel_gateway that has some different kernels on it. The goal is to send some code to the server via HTTP, and have one of the kernels execute the code and send a response back with the result of the code being executed (it will onnly execute functions and so it will always have a return value). Is there an API call I can make to send code to kernel_gateway and have the kernel execute the code?

--
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+unsubscribe@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/b144755a-43a3-4826-90f9-7b87a14259d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Roland Weber

unread,
Oct 9, 2017, 2:01:28 AM10/9/17
to Project Jupyter
Hello Andrew,

since you want to send the code for execution, you will have to run the kernel gateway in websocket mode. That means it's not a simple HTTP/REST call with "execute this" in the request and "here's the result" in the response. The sequence is more like:

1. Check if an instance of the kernel is already running.
1a. Yes: get the ID of that instance.
1b No: start a new instance and use that ID.
2. Connect to the kernel via websocket.
3. Send code for execution through websocket.
4. Receive the result through websocket.
4a. If execution fails, you might see helpful error messages on other channels, also through websocket.
5. Disconnect from the kernel.

Have a look at this if you're working with JavaScript:

If you knew in advance what functions have to be executed, you could run the kernel gateway in notebook mode and get a simple request/response API. The notebook mode currently supports only a single notebook and kernel. You could either run one gateway for each kernel you need, or enhance the kernel gateway code to suit your needs.

hope that helps,
  Roland
Reply all
Reply to author
Forward
0 new messages