Python/Node ZeroRPC 心跳错误
我正在尝试运行ZeroRPC网站上的Python服务器和Node.js客户端的HelloWorld示例。所有相关的库似乎都安装得很好,但在运行示例时,我遇到了这个错误:
{ name: 'HeartbeatError',
message: 'Lost remote after 10000ms',
traceback: '' }
有没有人遇到过这个问题?
2 个回答
0
如果可以的话,使用 gevent.sleep 来给 zerorpc 足够的时间去处理等待中的消息,包括心跳信号。
2
我在使用“zerorpc”: "^0.9.3"的时候,遇到了同样的问题,特别是在运行一些耗时的Python代码时。解决这个问题的方法是,你需要修改zerorpc库的代码,具体步骤是:进入node_modules文件夹,然后找到zerorpc,再进入lib文件夹,最后打开channel.js文件。
在这个文件中,找到对应的方法并进行修改:
//Runs the heartbeat on this channel
Channel.prototype._runHeartbeat = function() {
var self = this;
return setInterval(function() {
if(util.curTime() > self._heartbeatExpirationTime) {
//If we haven't received a response in 2 * heartbeat rate, send an
//error
// self.emit("heartbeat-error", "Lost remote after " + (HEARTBEAT * 2) + "ms");
// self.close();
}
//Heartbeat on the channel
try {
var event = events.create(self._envelope, self._createHeader(), "_zpc_hb", [0]);
self._socket.send(event);
} catch(e) {
console.error("Error occurred while sending heartbeat:", e);
}
}, HEARTBEAT);
};
在最新的代码中,你可以在GitHub上找到:https://github.com/dotcloud/zerorpc-node,他们已经解决了这个问题。