This code is runnable
I get an empty array “link”
although I should get an array with objects in it,
when I print link in func_b it is not empty
Self should refer to the object, but I guess this is not the case with multiprocessing, it seems to be some kind of copy
Does anyone know a solution ?
THX
class class_b:
def __init__(self):
self.counter=0
self.sum=[]
class class_a:
import random as ran
from multiprocessing import Pool
import os
def __init__(self):
self.link=[0]*50
self.arr_a=[0]*100
def func_b(self,arg):
arr_key=self.ran.randint(0, 50)
if self.link[arr_key] ==0:
self.link[arr_key]=class_b()
else:
obj=self.link[arr_key]
obj.counter+=1
(obj.sum).append(self.ran.randint(0,10))
print(self.link)
def func_a(self):
with self.Pool(processes=self.os.cpu_count()) as pool:
pool.map(self.func_b,enumerate(self.arr_a))
print(self.link)
def task():
obj=class_a()
obj.func_a()
if __name__ == '__main__':
task()
1