【发布时间】:2015-03-07 16:47:48
【问题描述】:
我正在尝试在节点和衍生的 Python 进程之间实现简单的双向通信。
Python:
import sys
for l in sys.stdin:
print "got: %s" % l
节点:
var spawn = require('child_process').spawn;
var child = spawn('python', ['-u', 'ipc.py']);
child.stdout.on('data', function(data){console.log("stdout: " + data)});
var i = 0;
setInterval(function(){
console.log(i);
child.stdin.write("i = " + i++ + "\n");
}, 1000);
在 Python 上使用 -u 会强制无缓冲 I/O,因此我希望看到输出(我也尝试过 sys.stdout.flush())但没有。我知道我可以使用child.stdout.end(),但这会阻止我以后写入数据。
【问题讨论】: