pygameを使用してPythonでターン制ストラテジーゲームを作成しています。ソケットを書くのは非常に難しいと思ったので、ゲームボードの状態を共有するためにPyroに頼りました。ただし、Pyroは一度に2つ以上の接続をサポートできないようです。
ローカルホストでネームサーバーを実行しています
python -m Pyro4.naming
テストケース'サーバー':
import Pyro4
class Testcase:
def __init__(self):
self.values = [1, 2, 3, 10, 20, 30]
def askvalue(self, i):
return self.values[i]
daemon = Pyro4.Daemon()
ns = Pyro4.locateNS()
uri = daemon.register(Testcase())
ns.register("thetest", uri)
daemon.requestLoop()
およびクライアント:
import Pyro4, time
ns = Pyro4.locateNS()
casetester = Pyro4.Proxy("PYRONAME:thetest")
while True:
print "Accessing remote object:"
print casetester.askvalue(1)
print "staying busy"
time.sleep(10)
最初の2つのクライアントからの出力:
/usr/local/lib/python2.7/dist-packages/Pyro4-4.14-py2.7.egg/Pyro4/core.py:155: UserWarning: HMAC_KEY not set, protocol data may not be secure
warnings.warn("HMAC_KEY not set, protocol data may not be secure")
Accessing remote object:
2
staying busy
Accessing remote object:
2
staying busy
繰り返します
3番目のクライアントからの出力:
/usr/local/lib/python2.7/dist-packages/Pyro4-4.14-py2.7.egg/Pyro4/core.py:155: UserWarning: HMAC_KEY not set, protocol data may not be secure
warnings.warn("HMAC_KEY not set, protocol data may not be secure")
Accessing remote object:
とハングします。
4番目、5番目(そしておそらくそれ以降)のクライアントからの出力:
/usr/local/lib/python2.7/dist-packages/Pyro4-4.14-py2.7.egg/Pyro4/core.py:155: UserWarning: HMAC_KEY not set, protocol data may not be secure
warnings.warn("HMAC_KEY not set, protocol data may not be secure")
この段階で、ネームサーバーに^ Cを指定し、クライアント3、4、...にこの出力を指定してクラッシュします。
Traceback (most recent call last):
File "client.py", line 3, in <module>
ns = Pyro4.locateNS()
File "/usr/local/lib/python2.7/dist-packages/Pyro4-4.14-py2.7.egg/Pyro4/naming.py", line 323, in locateNS
raise Pyro4.errors.NamingError("Failed to locate the nameserver")
Pyro4.errors.NamingError: Failed to locate the nameserver
その間、クライアント1と2はビジー状態のままです。
ただし、アクティブなクライアントの1つを切断すると、ハングしたクライアントの1つが動作を開始します。
「exportPYRO_SERVERTYPE=multiplex」を使用してスレッドから切り替えようとしましたが、動作は変わりませんでした。最大接続数の設定は200のようです。1000に設定しても問題は解決しませんでした。
Pyroにはスケーラビリティがないことを読みましたが、少なくとも10の接続に到達できることは確かですか?
一度に3つ以上のクライアントをPyro4オブジェクトに接続するにはどうすればよいですか?