我正在尝试为Jupyter编写一个简单的内核。主要我已经为Jupiter客户实现了Messaging一章。因此,我想支持内核和jupyter客户端之间的基本行为(用于回答user3666197的问题)。
内核必须实现execute和kernel info消息才能使用。我参考了指南simple kernel中的示例,并为heartbeat
,shell
和一些iopub
实现了基本答复。它最终进入了交互式外壳。但是,当我尝试执行一个简单的表达式时,它不起作用。
sent:(e8c20816-91165208e6bc7f347ea2a6ca <IDS|MSG> dfd689cbb6096009dd12d45641b23a0126274447f79d59ad3a906d062d6e8e42 {"username":"kernel","msg_type":"kernel_info_reply","version":"5.0","session":"0a3ebc64-6b2e-4b67-90ce-93f1d7ea5e00","msg_id":"6a0258f2-6a18-464e-987c-2a779d2f4d77","date":"2019-07-25T13:03:15"} {"username":"xxxx","msg_type":"kernel_info_request","version":"5.3","msg_id":"033ffc11-fd3b9d6584cda3c53c3af6af","session":"e8c20816-91165208e6bc7f347ea2a6ca","date":"2019-07-25T11:03:14.738975Z"} {} {"banner":"","implementation":"chezscheme","protocol_version":"5.0","language_info":{"file_extension":".ss","nbconvert_exporter":"","mimetype":"ss","codemirror_mode":"","version":"9.5.2","name":"chezscheme","pygments_lexer":""},"implementation_version":"0.0.1"})
recv:(e8c20816-91165208e6bc7f347ea2a6ca <IDS|MSG> 1e70faf328208ad05cccf0d81cf528d97572ecd117d015030912d00603c86687 {"msg_id":"a79fc413-cf77b34c17501824cf99560e","msg_type":"history_request","username":"xxx","session":"e8c20816-91165208e6bc7f347ea2a6ca","date":"2019-07-25T11:03:15.873079Z","version":"5.3"} {} {} {"raw":true,"output":false,"hist_access_type":"tail","n":1000})
unhandled history request
Exception in bytevector-length: #<void> is not a bytevector
/Users/xxxx/Documents/Personal/Project/venv/lib/python3.7/site-packages/jupyter_console/ptshell.py:103: UserWarning: No lexer found for language ''. Treating as plain text.
warn("No lexer found for language %r. Treating as plain text." % name)
Jupyter console 6.0.0
[ZMQTerminalIPythonApp] Starting the jupyter console mainloop...
In [1]: (+ 1 1)
/Users/xxx/Documents/Personal/Project/venv/lib/python3.7/site-packages/jupyter_console/ptshell.py:661: UserWarning: The kernel did not respond to an is_complete_request. Setting `use_kernel_is_complete` to False.
warn('The kernel did not respond to an is_complete_request. '
In [1]:
它返回了警告消息,但未返回任何结果。
警告是:
/Users/XXXX/Documents/Personal/Project/venv/lib/python3.7/site-packages/jupyter_console/ptshell.py:661: UserWarning: The kernel did not respond to an is_complete_request. Setting `use_kernel_is_complete` to False.
warn('The kernel did not respond to an is_complete_request. '
所以我认为有两个问题需要回答:
is_complete_request
的答复?execute_request
的答复?在回答两个问题之前,我需要确保内核确实收到了这些请求。因此,我在内核中添加了一个dealer
套接字以重定向所有收到的shell
消息,并在独立的服务器中运行了一个router
套接字以接收所有重定向的shell
消息。 (我添加此日志服务器的原因是,我不知道如何在前台进入交互式shell后打印出消息。我尝试将iopub
与msg-type
{{1} }不能按预期工作。)
我发现内核只有3条stream
消息:
2 x shell
,
1 x kernel_info_request
应该证明shell套接字是有效的,因为内核必须在进入交互式shell之前回复history_request
。但是,我没有收到任何kernel_info_request
或is_complete_request
。因此,我对如何继续工作一无所知。