If you just want to access it, you can. You can read data from global variables across all processes created by multiprocessing
.
However if you want to write into for example a dictionary (with caution not to overwrite) you can use shared memory objects. multiprocessing
has a built in manager
from where you can call all the shared memory objects such as lists, dicts.
You pass all your objects in arguments, so it will be available for all of the processes, however if you make changes inside the object it wont we permanent, as it would not be permanent with a simple function.
Simple example for a numpy array:
import numpy as np
import multiprocessing
a = np.zeros(5)
def func(b):
ns.array += b
return
manager = multiprocessing.Manager()
ns = manager.Namespace()
ns.array = np.zeros(5)
pool = multiprocessing.Pool(2)
list(pool.imap_unordered(func, [1,2]))
print(ns.array)
Will output [ 3. 3. 3. 3. 3.]
Here is another very detailed solution: https://stackoverflow.com/a/7908612/4555249