1
멀티 프로세싱, 나는 getattr에서 RecursionError를 얻을.파이썬 객체 조성과 내가 <strong>getattr</strong>와 객체의 구성을 구현하고 새로운 프로세스로 객체를 전달하면
from multiprocessing import Pool
class Bar:
def __init__(self, bar):
self.bar = bar
class Foo:
def __init__(self, bar):
self._bar = bar
def __getattr__(self, attr):
try:
return getattr(self._bar, attr)
except RecursionError:
print('RecursionError while trying to access {}'.format(attr))
raise AttributeError
def f(foo):
print(foo.bar)
if __name__ == '__main__':
foo = Foo(Bar('baz'))
f(foo)
p = Pool(1)
p.map(f, [foo])
출력은 이것이다 :
baz
RecursionError while trying to access _bar
baz
왜 푸가 _bar 속성을 찾을 수없는 및 getattr에 의존하는 다음 예는?
이것은 무엇입니까?'foo = Foo (Bar ('baz'))'? 그것은 당신의 의견으로 무엇을합니까? –