Pyro4 を使用してサーバー上で関数を実行しようとしています。コードを見てください: =========================Client================ ======
import Pyro4
def square(x):
return x**2
remoteServer = Pyro4.Proxy('PYRONAME:server')
print(remoteServer.evaluate(square, 4))
===========================サーバー===================== ====
import Pyro4
class Server(object):
def evaluate(self, func, args):
return func(*args)
def main():
server = Server()
Pyro4.Daemon.serveSimple({server: "server"},ns=True)
if __name__ == '__main__':
main()
========================ネーミングサーバー=======================
import Pyro4
Pyro4.naming.startNSloop()
================================================== =========
エラーが発生しました: " Pyro4.errors.ConnectionClosedError: received: not enough data ". 以下の完全なスタック トレースを見てください。
Traceback (most recent call last):
File "C:\Users\Alex\Desktop\2.py", line 9, in <module>
print(remoteServer.evaluate(square, 4))
File "C:\Users\Alex\AppData\Roaming\Python\Python34\site-packages\Pyro4\core.py", line 169, in __call__
return self.__send(self.__name, args, kwargs)
File "C:\Users\Alex\AppData\Roaming\Python\Python34\site-packages\Pyro4\core.py", line 380, in _pyroInvoke
msg = message.Message.recv(self._pyroConnection, [message.MSG_RESULT], hmac_key=self._pyroHmacKey)
File "C:\Users\Alex\AppData\Roaming\Python\Python34\site-packages\Pyro4\message.py", line 161, in recv
msg = cls.from_header(connection.recv(cls.header_size))
File "C:\Users\Alex\AppData\Roaming\Python\Python34\site-packages\Pyro4\socketutil.py", line 460, in recv
return receiveData(self.sock, size)
File "C:\Users\Alex\AppData\Roaming\Python\Python34\site-packages\Pyro4\socketutil.py", line 195, in receiveData
raise err
Pyro4.errors.ConnectionClosedError: receiving: not enough data
メソッド(関数)に渡された関数をサーバーに実行させたい。
PS: Windows7、Python 3.4.1
同様の質問 ( How to send a function to a remote Pyro object ) を見つけましたが、うまくいきませんでした。コールバック デコレーター @pyro4.callback を使用しようとしましたが、公式の例 ( https://github.com/delmic/Pyro4/tree/master/examples/callback : server2.py, client2.py) でさえ機能しませんでした (python を使用) 3.4 および python 2.7) => メッセージのみ:「サーバー: クライアントへのコールバック 1 を実行しています」が表示され、何も起こりません。
ありがとう