from multiprocessing import Process
class B:
def __init__(self, a, b):
self.a = a
self.b = b
class A:
def __init__(self, a):
self.k = None
self.k2 = None
p1 = Process(target=self.a1, args=(a, 1,), daemon=True)
p2 = Process(target=self.a2, args=(a, 2,), daemon=True)
p1.start()
p2.start()
p1.join()
p2.join()
def a1(self, a, b):
self.k = B(a, b)
def a2(self, a, b):
self.k2 = B(a, b)
if __name__ == '__main__':
t = A(0)
print(t.k)
The project plans that class B will be large and will contain a large number of calculations. I wanted to divide the creation of a class into streams, but I can’t save the variable k. Why is the variable k always None? How to fix?