我有两个流程:
第一个过程是经理.py从背景开始:
from multiprocessing.managers import SyncManager, BaseProxy
from CompositeDict import *
class CompositeDictProxy(BaseProxy):
_exposed_ = ('addChild', 'setName')
def addChild(self, child):
return self._callmethod('addChild', [child])
def setName(self, name):
return self._callmethod('setName', [name])
class Manager(SyncManager):
def __init__(self):
super(Manager, self).__init__(address=('127.0.0.1', 50000), authkey='abracadabra')
def start_Manager():
Manager().get_server().serve_forever()
if __name__=="__main__":
Manager.register('get_plant', CompositeDict, proxytype=CompositeDictProxy)
start_Manager()
第二个是消费者.py应该使用管理器中定义的注册对象:
^{pr2}$在后台运行管理器,然后消费者我得到错误消息: 运行时错误:超过最大递归深度, 当使用addChild到消费者时,我可以正确使用setName。在
方法addChild和setName属于compositedit,我假设是代理。在
怎么了?在
compositedit重写本机getattr勖方法并包含在错误消息中。我想,在某种程度上,它没有使用正确的方法。如果是这样的话,我怎么解决这个问题??在
详细的错误消息是:
Traceback (most recent call last):
File "consumer.py", line 21, in <module>
Consumer()
File "consumer.py", line 17, in __init__
plant.addChild('beta')
File "<string>", line 2, in addChild
File "/usr/lib/python2.5/site-packages/multiprocessing-2.6.1.1-py2.5-linux-i686.egg/multiprocessing/managers.py", line 729, in _callmethod
kind, result = conn.recv()
File "/home/--/--/CompositeDict.py", line 99, in __getattr__
child = self.findChild(name)
File "/home/--/--/CompositeDict.py", line 185, in findChild
for child in self.getAllChildren():
File "/home/--/--/CompositeDict.py", line 167, in getAllChildren
l.extend(child.getAllChildren())
File "/home/--/--/CompositeDict.py", line 165, in getAllChildren
for child in self._children:
File "/home/--/--/CompositeDict.py", line 99, in __getattr__
child = self.findChild(name)
File "/home/--/--/CompositeDict.py", line 185, in findChild
for child in self.getAllChildren():
File "/--/--/prove/CompositeDict.py", line 165, in getAllChildren
for child in self._children:
...
File "/home/--/--/CompositeDict.py", line 99, in __getattr__
child = self.findChild(name)
File "/home/--/--/CompositeDict.py", line 185, in findChild
for child in self.getAllChildren():
RuntimeError: maximum recursion depth exceeded
除了修复上面的许多我认为是意外的错误(}、错误声明等的几个实例),关键是要将
init
必须是__init__
,您丢失了{manager.py
中的注册变成:不知道您要用
lambda
作为第二个参数来实现什么,但是第二个参数必须是生成所需类型的可调用参数,而不是像您使用的那样生成两个项元组的类型。在相关问题 更多 >
编程相关推荐