问题描述
基于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 (将#修改为@)