如何解决__getattribute__不适用于多处理BaseManager
更新:
调用DataTemplate
也不起作用(相同错误)
基于this post,似乎通过使用foo.__getattribute__("_a")
并将NamespaceProxy
添加到公开的方法,我应该能够直接访问共享对象的属性。但是,我不断收到有关该属性不存在的错误。这是代码:
__getattribute__
输出:
class Foo:
def __init__(self):
self._a = 1000
def get_a(self):
return self._a
class SharedFoo(NamespaceProxy):
_exposed_ = ('__getattribute__','__setattr__','__init__','get_a')
def get_a(self):
callmethod = object.__getattribute__(self,'_callmethod')
return callmethod('get_a',())
class MyManager(BaseManager):
pass
def test():
MyManager.register('SharedFoo',Foo,SharedFoo)
with MyManager() as manager:
foo = manager.SharedFoo()
print(foo.get_a())
print(foo._a)
我尝试将1000
# some random traceback
File "path/to/test.py",line 318,in test
print(foo._a)
File "path/to/lib/python3.7/multiprocessing/managers.py",line 1097,in __getattr__
return object.__getattribute__(self,key)
AttributeError: 'SharedFoo' object has no attribute '_a'
更改为__getattribute__
,但是我一直遇到相同的错误。我该如何解决?
谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。