Pyro4不允许多于两个客户端访问一个URI [英] Pyro4 does not allow more than two clients to access one URI

查看:229
本文介绍了Pyro4不允许多于两个客户端访问一个URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用pygame在Python中创建一个基于回合的策略游戏。我发现书写插槽难以置信,所以我转向Pyro分享游戏板的状态。但是,Pyro似乎一次不能支持超过2个连接。



我通过

在localhost上运行一个名称服务器

  python -m Pyro4.naming 

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()

p>

  import Pyro4,time 

ns = Pyro4.locateNS()

casetester = Pyro4.Proxy(PYRONAME:thetest)

while True:
print访问远程对象:
print casetester.askvalue(1)
print保持繁忙
time.sleep(10)

从前两个客户端输出: / p>

  /usr/local/lib/python2.7/dist-packages/Pyro4-4.14-py2.7.egg/Pyro4/ core.py:155:UserWarning:HMAC_KEY未设置,协议数据可能不安全
warnings.warn(HMAC_KEY未设置,协议数据可能不安全)
访问远程对象:
2
保持繁忙
访问远程对象:
2
保持繁忙


b $ b

并重复



来自第三个客户端的输出:

  /usr/local/lib/python2.7/dist-packages/Pyro4-4.14-py2.7.egg/Pyro4/core.py:155:UserWarning:未设置HMAC_KEY,协议数据可能不安全
warnings.warn(HMAC_KEY未设置,协议数据可能不安全)
访问远程对象:


$


$ b

  /usr/local/lib/python2.7/dist-packages/Pyro4-4.14-py2.7.egg/Pyro4/core.py:155:UserWarning:HMAC_KEY not set ,协议数据可能不安全
warnings.warn(HMAC_KEY未设置,协议数据可能不安全)

在这个阶段,我给名字服务器a ^ C,客户端3,4,...给出这个输出并崩溃:

  Traceback(最近一次调用):
文件client.py,第3行,在< module>
ns = Pyro4.locateNS()
文件/usr/local/lib/python2.7/dist-packages/Pyro4-4.14-py2.7.egg/Pyro4/naming.py,行323,in locateNS
raise Pyro4.errors.NamingError(无法找到名称服务器)
Pyro4.errors.NamingError:无法找到名称服务器

同时客户端1和2保持忙碌。



其中一个已经开始操作。



我已经尝试通过export PYRO_SERVERTYPE = multiplex从线程切换,但这并没有改变行为。最大连接设置似乎是200.设置为1000也没有解决我的问题。



我读过Pyro缺乏可扩展性,但肯定我会能够到达至少10个连接?



如何一次连接多个客户端到Pyro4对象?

解决方案

回答自己的问题,希望这会迅速显示在Google上!



这不是一个完美的答案,但它是一个工作kludge。服务器代码保持不变,但客户端代码变为:

  import Pyro4,time 

b $ b全局ns
全局casetester

def connect():
全局ns
全局casetester
ns = Pyro4.locateNS()
casetester = Pyro4.Proxy(PYRONAME:thetest)

def disconnect():
全球ns
全球casetester
del ns
del casetester


while True:
print访问远程对象:
connect()
print casetester.askvalue(1)
disconnect )
printstaying busy
time.sleep(3)

全球在所有的地方,因为从不承担。



为什么这样工作?因为我建立连接,访问远程对象,然后删除连接。



我发现这个解决方案很丑陋,但我会使用它,直到我找到 方式。


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?

解决方案

Answering my own question, hopefully this will appear on google swiftly!

This is not a "perfect" answer, but it is a working kludge. The server code stays the same, but the client code becomes:

import Pyro4, time


global ns
global casetester

def connect():
    global ns
    global casetester
    ns = Pyro4.locateNS()
    casetester = Pyro4.Proxy("PYRONAME:thetest")

def disconnect():
    global ns
    global casetester
    del ns
    del casetester


while True:
    print "Accessing remote object:"
    connect()
    print casetester.askvalue(1)
    disconnect()
    print "staying busy"
    time.sleep(3)

extra "Global" all over the place because never assume.

Why does this work? Because I make a connection, access the remote object, and then delete the connections.

I find this solution very ugly, but I will use it until I find the "right" way.

这篇关于Pyro4不允许多于两个客户端访问一个URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆