When I use multiprocessing
to create some processes, it seems that processes have the same state
. How does it work?
I want each process has different state, so that the data created by numpy.random
is indepenedent. One way is to use pid
as seed, is there a more elegent approach?
from multiprocessing import Pool
import numpy as np
import os
def f(x):
print(f'{os.getpid()}: {np.random.get_state()}')
print(f'{os.getpid()}: {np.random.rand(5)}')
if __name__ == '__main__':
with Pool(5) as p:
p.map(f, [None] * 5)