'How to Override Values In-Place for List using MultiProcessing in Python 3?

I've been trying to Run the following Code:

from math import inf
import multiprocessing

dist = [[inf] * n for _ in range(n)]

n = 8
data = [i for i in range(n)]

def set_self_distance(data):
    for i in range(data[0],data[-1]):
        dist[i][i] = 0

processes = multiprocessing.cpu_count()
pool = multiprocessing.Pool(processes=processes)
size = int(math.ceil(float(len(data)) / processes))
data = [data[i * size:(i + 1) * size] for i in range(processes)]
pool.map(set_self_distance, data)

I've tried various versions and have the following issues:

  • Either getting 'n' copies of dist[ ][ ] inside dist ||OR||
  • There is no change at all in dist[ ][ ].

EDIT : Added Missing Code Definition for dist[ ][ ].
I want to Update Values using MultiProcessing In-Place in the List 'dist [ ][ ]'.
Thank You :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source