Erlang中的IPython语言内核实现 [英] IPython Language Kernel Implementation in Erlang
问题描述
我有工作:
- 启动ipython控制台和erlang内核
- Erlang内核读取内核内容.json文件,其中包含zmq的所有端口号
- 为
shell创建zmq绑定
,heartbeat
,控制
,iopub
使用erlzmq2库的套接字。 - 创建的函数来解析来自IPython的消息
- 创建一个流程,让心跳服务器运行并返回消息到IPython
- 创建一个进程以便Shell套接字接收并响应以下消息
- kernel_info_request - > kernel_info_reply
- execute_request - > execute_reply
- 此外,iopub套接字发送这些消息
- status
- 杓ut
如果你还在我身边,所有这些都有效果。
第一个IPython 在[1]中:
提示出现,我可以键入代码,发送到后端并从ipython接收execute_request消息。
但是,我的问题是在我收到一个execute_request的这个事件序列之后:
- 发送执行IPython的一个忙碌状态
- 执行代码并捕获输出字符串
- 发送pyout消息到IPython
- 发送execute_reply到IPython
- 将空闲状态发送到IPython
发送这些消息后,什么都没发生。我不再收到来自IPython的消息,代码执行不会输出到控制台,新的提示也不会要求更多的用户输入。
我只是想知道我是按正确的顺序发送邮件,还是发送正确的邮件?
我已经在这个工作了几个星期了,我找不到控制台问题的解决方案
但是,我发现一个可以多个输入的解决方法。
首先我没有使用我以前使用的语言配置文件。这个语言简介只是告诉IPython要使用什么内核和使用什么加密字符串。
下一步,我开始使用笔记本而不是安慰。希望能提供更多的投入。而且,它是。 :)
要使用指定的内核启动ipython,我使用以下命令:
code> ipython2笔记本--KernelManager.kernel_cmd ='[/ usr / lib / erlang / bin / escript,ipython_kernel.erl,{connection_file}]'--Session.key = - -Session.keyfile =
在上述命令中,我指定内核命令,并提供以下内容:
- 运行我的erlang内核的可执行文件的位置
- 我的内核的名称
- 和连接文件
strong>,我将会话密钥和会话密钥文件指定为空字符串。
提供内核正确写入,它允许多个条目输入到ipyton / ierlang
以下是ierlang早期阶段的示例:
我希望这篇文章可以帮助任何人努力为ipython开发内核。 :)
[更新 - 2014年4月12日]
我终于弄清楚了这个问题。事实证明,当通过zmq发送erlang字符串(ints列表)时,他们以IP列表的形式发送IPython的消息解析器。
我推测,他们会自动
解决方案
解决方案是编辑 IPython / kernel / zmq / session.py
文件以允许它解析erlang字符串。
这允许输出提示出现在控制台和笔记本版本的IErlang中。
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
- status
- pyout
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.
这篇关于Erlang中的IPython语言内核实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!