我的设置产生了一个 Node.js 子节点,它使用 Python 对象创建了一个 2 向 ZeroRPC 会话对。
python端类似这样:
class MyClass:
def __init__(self, socketpath):
self.client = zerorpc.Client()
self.client.connect(socketpath)
def sendtoclient(self, msg):
self.client.receiveMessage(msg)
if __name__ == '__main__':
zpc = zerorpc.Server(MyClass(sys.argv[1]))
zpc.bind(sys.argv[1] + "_python")
zpc.run()
Node.js 子客户端可以调用 Python 服务器上的方法,但该服务器中的客户端无法在 Node.js 子服务器上调用而不出现异常:
Traceback (most recent call last):
File "/usr/lib64/python2.6/site-packages/gevent/queue.py", line 271, in _unlock getter.switch(getter)
File "/usr/lib64/python2.6/site-packages/gevent/hub.py", line 534, in switch assert getcurrent() is self.hub, "Can only use Waiter.switch method from the Hub greenlet"
AssertionError: Can only use Waiter.switch method from the Hub greenlet
<callback at 0x3055e90 args=()> failed with AssertionError
Python 类中的客户端是否需要作为 gevent 生成,然后receiveMessage
在需要时调用其方法?还是我忽略了其他一些技巧?