I'm currently building an Erlang language kernel backend for IPython, and I'm testing it out in the console.
What I have working:
- Start ipython console and the erlang kernel
- Erlang kernel reads contents of kernel.json file which contains all the port numbers for zmq
- Create zmq bindings for the
shell
, heartbeat
, control
, iopub
sockets using the erlzmq2 library.
- Created functions to parse messages from IPython
- Create a process for the heartbeat server to run on and return messages to IPython
- Created a process for the Shell Socket to receive and respond to the following messages
- kernel_info_request -> kernel_info_reply
- execute_request -> execute_reply
- Also, the iopub socket sends these messages
If you're still with me, all of this works.
The first IPython In[1]:
prompt appears and I can type code, send it to the backend and receive the execute_request message from ipython.
However, my problem is after this sequence of events where I receive an execute_request:
- sent a busy status to IPython
- executed the code and captured the output string
- sent pyout message to IPython
- sent execute_reply to IPython
- sent idle status to IPython
After these messages are sent, nothing happens. I receive no more messages from IPython and the code execution is not output to the console, nor does a new prompt appear requesting more input from the user.
I'm just wondering if I'm sending the messages in the correct order, or am I sending the correct messages?
I've been working on this for a couple of weeks now, and I've found no solution to the console problem.
However, I've found a work-around that allows more than one input.
Firstly I did not use the language profile I had previously used. This language profile simply tells IPython what kernel to use and what encryption string to use.
Next, I started to use the notebook instead of the console. In the hope it would offer more inputs. And, it did. :)
To start ipython with a specified kernel, I used the following command:
ipython2 notebook --KernelManager.kernel_cmd='["/usr/lib/erlang/bin/escript", "ipython_kernel.erl", "{connection_file}"]' --Session.key="" --Session.keyfile=""
In the above command, I specify the kernel command, and provide the following:
- the location of the executable to run my erlang kernel
- the name of my kernel
- and connection file
Next, I specify the session key and the session keyfile as empty strings.
Providing the kernel is correctly written, it allows multiple entries of code and markdown into ipyton/ierlang.
Here is a sample of ierlang at it's early stages:
I hope this post helps out anyone else that's struggling to develop kernels for ipython. :)
[Update- April 12, 2014]
I finally figured out the problem. It turns out, when sending erlang strings(list of ints) over zmq, they arrive at IPython's message parser as a list of ints.
I presumed, they'd automatically convert to strings, but they don't.
Solution
The solution was to edit the IPython/kernel/zmq/session.py
file to allow it to parse erlang strings.
This has allowed for the output prompt to appear in the console and in the notebook versions of IErlang.