如果我有一个 python 类
from multiprocessing import Process
class A(Process):
def run(self):
self.var = "asdf"
def pprint(self):
print(self.var)
if __name__ == "__main__":
foo = A()
foo.start()
foo.pprint()
bar = A()
bar.pprint()
我得到回溯错误
Traceback (most recent call last):
File "simple.py", line 13, in <module>
foo.pprint()
File "simple.py", line 8, in pprint
print(self.var)
AttributeError: 'A' object has no attribute 'var'
我可以访问在 run 函数中定义的实例变量,以及在类范围内定义的其他函数吗?