使用Node.js与iPython内核交谈 - 对kernel_info_request没有响应

时间:2015-04-04 15:50:07

标签: node.js ipython

我正在通过shell通道从node.js脚本向正在运行的iPython内核发送 kernel_info_request ,但我没有收到回复。有人看到我做错了吗?

这是IPython连接文件ipker.json。请注意,我将设置为“”,以避免此时必须处理签名。

{
  "stdin_port": 60304, 
  "ip": "127.0.0.1", 
  "control_port": 59733, 
  "hb_port": 39868, 
  "signature_scheme": "hmac-sha256", 
  "key": "", 
  "shell_port": 51314, 
  "transport": "tcp", 
  "iopub_port": 55548
}

以下是我启动IPython内核的方法:

$ ipython kernel --IPKernelApp.log_level=10 --IPKernelApp.connection_file=./ipker.json

这是node.js:

var fs = require('fs');
var zmq = require('zmq');

var kernel = JSON.parse(fs.readFileSync("ipker.json"));

var shell_socket = zmq.socket('req');
var shell_addr = kernel.transport + "://" + kernel.ip + ":" + kernel.shell_port;
console.log("\nConnecting shell socket at " + shell_addr + "...");
shell_socket.connect(shell_addr);

shell_socket.on("message", function(msg){console.log("\nShell socket says:\n"); console.log(toString(msg))});

var header = {"msg_id": "12345", "msg_type": "kernel_info_request"};
var parent_header = {};
var metadata = {};
var content = {};
shell_socket.send(["","<IDS|MSG>","", JSON.stringify(header), JSON.stringify(parent_header), JSON.stringify(metadata), JSON.stringify(content)]);

我在控制台上看到的输出是:

在tcp://127.0.0.1:51314 ...

连接shell套接字

Shell套接字说:

[object Undefined]

这是IPython内核的输出。它似乎正在传达信息并制定答复......

    $ipython kernel --IPKernelApp.log_level=10 --IPKernelApp.connection_file=./ipker.json
    [IPKernelApp] Config changed:
    [IPKernelApp] {'IPKernelApp': {'log_level': 10, 'connection_file': u'./ipker.json'}}
    [IPKernelApp] Using existing profile dir: u'/home/mgreenbe/.config/ipython/profile_default'
    [IPKernelApp] Searching path [u'/home/mgreenbe/Dropbox/Projects/node/zmq', u'/home/mgreenbe/.config/ipython/profile_default'] for config files
    [IPKernelApp] Attempting to load config file: ipython_config.py
    [IPKernelApp] Loaded config file: /home/mgreenbe/.config/ipython/profile_default/ipython_config.py
    [IPKernelApp] Config changed:
    [IPKernelApp] {'Session': {'key': ''}, 'IPKernelApp': {'log_level': 10, 'connection_file': u'./ipker.json'}, 'ProfileDir': {}}
    [IPKernelApp] Loading connection file /home/mgreenbe/Dropbox/Projects/node/zmq/ipker.json
    [IPKernelApp] Starting the kernel at pid: 3439
    [IPKernelApp] shell ROUTER Channel on port: 51314
    [IPKernelApp] iopub PUB Channel on port: 55548
    [IPKernelApp] stdin ROUTER Channel on port: 60304
    [IPKernelApp] control ROUTER Channel on port: 59733
    [IPKernelApp] Heartbeat REP Channel on port: 39868
    [IPKernelApp] To connect another client to this kernel, use:
    [IPKernelApp]     --existing ./ipker.json
    NOTE: When using the `ipython kernel` entry point, Ctrl-C will not work.

    To exit, you will have to explicitly quit this process, by either sending "quit" from a client, or using Ctrl-\ in UNIX-like environments.

    To read more about this, see https://github.com/ipython/ipython/issues/2049

    To connect another client to this kernel, use:
        --existing ./ipker.json
    [IPKernelApp] Writing connection file: ./ipker.json
    [IPKernelApp] Loading IPython extensions...
    [IPKernelApp] Loading IPython extension: storemagic
    [IPKernelApp] 
    *** MESSAGE TYPE:kernel_info_request***
    [IPKernelApp]    Content: {}
       --->    
    [IPKernelApp] {'parent_header': {'msg_id': '12345', 'msg_type': 'kernel_info_request'}, 'msg_type': 'kernel_info_reply', 'msg_id': 'c7c36418-4484-4ef7-868e-18c14fbe76be', 'content': {'protocol_version': [4, 0], 'language_version': [2, 7, 6], 'language': 'python', 'ipython_version': [1, 2, 1, '']}, 'header': {'date': datetime.datetime(2015, 4, 5, 15, 50, 6, 437444), 'username': u'kernel', 'session': u'ab0783e9-ac7a-4c12-90ac-751687de6993', 'msg_id': 'c7c36418-4484-4ef7-868e-18c14fbe76be', 'msg_type': 'kernel_info_reply'}, 'tracker': , 'metadata': {}} 

有什么想法吗?

0 个答案:

没有答案