from multiprocessing import Process
import time, random
class Example:
pass
def fun(i, case):
time.sleep(random.randint(1, 4))
print("{}, age is {}".format(i, case.age))
def main():
for i in range(3):
setattr(Example, "age", i)
print("satrt", Example.age)
ps = Process(target=fun, args=(i, Example))
ps.start()
if __name__ == '__main__':
main()
代码如上所示, 但是最终在 fun 函数里面报了 AttributeError: type object 'Example' has no attribute 'age' 这个错误,setattr 没有生效, 请问一下大佬原因。

