I am creating a turn based strategy game in Python using pygame. I found writing sockets incredibly difficult, so I turned to Pyro for sharing the state of the game board. However, Pyro seems unable to support more than 2 connections at a time.
I am running a nameserver on localhost via
python -m Pyro4.naming
Test case 'server':
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()
and the clients:
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)
Output from the first two clients:
/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
and repeats
Output from the third client:
/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:
and hangs.
Output from the fourth, fifth (and presumably all beyond) client:
/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")
At this stage, I give the nameserver a ^C, and clients 3, 4, ... give this output and crash:
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
Meanwhile clients 1 and 2 stay busy.
However, breaking one of the active clients will let one of the hung up ones start to operate.
I have tried via "export PYRO_SERVERTYPE = multiplex" to switch away from threading, but this did not change the behavior. The setting for maximum connections seems to be 200. Setting it to 1000 did not resolve my issue either.
I've read that Pyro lacks scalability, but surely I will be able to get to at least 10 connections?
How can I connect more than two clients at a time to a Pyro4 object?