i'm trying to use multiprocessing.Pool to parallelize an operation on a set of class objects.
obj= []
for i in range(20):
obj.append(myClass(i))
pool= multiprocessing.Pool(processes=4)
pool.map(do_something, obj)
pool.map(do_something_else, obj)
and myClass and its function do_something and do_something_else are like this..
class myClass:
def __init__(self,i):
self.obj_id= i
self.value= 0
def do_something():
self.value = self.value + 1 #some operations
def do_something_else():
self.value = self.value * 99 #some operations
How can i do this parallelization? and will the 'value' of the original objects in obj get updated? Can anyone help me with a solution? Thanks in advance.