Pyro4.Daemon オブジェクトの requestLoop メソッドに問題があります。
私が望むのは、リモートで「stop()」メソッドを呼び出して requestLoop 関数を解放し、デーモンをシャットダウンすることです。
この小さな例は機能しません
サーバ
#!/usr/bin/python
# -*- coding: utf-8 -*-
from daemon import Pyro4
class Audit(object):
def start_audit(self):
with Pyro4.Daemon() as daemon:
self_uri = daemon.register(self)
ns = Pyro4.locateNS()
ns.register("Audit", self_uri)
self.running = True
print("starting")
daemon.requestLoop(loopCondition=self.still_running)
print("stopped")
self.running = None
def hi(self, string):
print string
def stop(self):
self.running = False
def still_running(self):
return self.running
def main():
# lancement de l'auditor
auditor = Audit()
auditor.start_audit()
if __name__ == "__main__" :
main()
クライアント
import Pyro4
def main():
with Pyro4.Proxy("PYRONAME:Audit") as au:
au.hi("hello")
au.hi("another hi")
au.stop()
私が期待しているのは、サーバーが「こんにちは」と「別のこんにちは」を出力してからシャットダウンすることです。
しかし、シャットダウンは行われず、サーバーは依然として requestloop メソッドでブロックされています。好きなだけプロキシを使用できます。
しかし、別のクライアントを作成すると、最初のリモート呼び出しでサーバーがシャットダウンし、クライアントがエラーをスローします。
Pyro4.errors.ConnectionClosedError: receiving: not enough data
私のすべてのテストでは、2番目のプロキシを作成し、サーバーでリクエストループを渡すために例外をスローする必要があると言っています。
この問題を解決する方法を知っている人はいますか?