Suppose I created an object A with an 2 dimension numpy array as attributes. Then I created 10 threads using Process API to randomly set the rows of A.
I want to know if I write the following code, whether self.x if shared among all the Process(thread), or every Process(thread) has just a copy?
If not shared, I will lose all the updates, right?
import numpy as np
from multiprocessing import Process
class A:
def __init__():
self.x = np.zeros((3,4))
def update():
threads = []
for i in range(10):
trd = Process(target=self.set, args=(i,))
threads.append(trd)
trd.start()
for i in range(10):
threads[i].join()
def set(i):
self.x[i/3] = np.random.rand(1,4)
if ___main___:
a = A()
a.update()