Here's a minimal example of what I want to achieve.
The global INIT_* values should be incremented by each process and made available for another function (print_locked in this example):
import multiprocessing as mp
INIT_NODE = mp.Value('i', 1000)
INIT_WAY = mp.Value('i', 1000)
INIT_REL = mp.Value('i', 1000)
def print_locked(a, b, c):
print(a.value, b.value, c.value)
def process_results(a):
with mp.Lock():
INIT_NODE.value += 20000000
INIT_WAY.value += 10000000
INIT_REL.value += 1000000
print_locked(INIT_NODE, INIT_WAY, INIT_REL)
def main():
"""Entry point for the program."""
a = range(5)
pool = mp.Pool(4)
pool.map(process_results, a)
if __name__ == '__main__':
main()
However, it seems that each process increments its own version of the initial values, which is exactly what I want to avoid.
Example output:
20001000 20001000 2001000
20001000 20001000 2001000
40001000 30001000 3001000
60001000 40001000 4001000
80001000 50001000 5001000