4 ms·
I tried this on a Linux machine in Py3 earlier, which I think is equivalent to your example: from multiprocessing import Pool shared = {} def f(x):
by hot_gril 2y ago
I tried this on a Linux machine in Py3 earlier, which I think is equivalent to your example:
from multiprocessing import Pool
shared = {}
def f(x):
global shared # idk if this matters but tried without it too
shared[x] = x
print(shared)
if __name__ == '__main__':
with Pool(5) as p:
p.map(f, [1, 2, 3])
print(shared)
It printed {1: 1}, {2: 2}, {3: 3} then {} at the end. So the parent and other children didn't see the change made by each child. Doesn't seem like they're RW sharing.
- Galanwe 2y agoYes, as mentioned, the workers get a copy of the interpreter states. Every modification made in a worker to these objects stay local to the worker. These tricks are for sending data to a worker, not receiving back data.