I want to be able to use the Values module from the multiprocessing library to be able to keep track of data. As far as I know, when it comes to multiprocessing in Python, each process has it's own copy, so I can't edit global variables. I want to be able to use Values to solve this issue. Does anyone know how I can pass Values data into a pooled function?
from multiprocessing import Pool, Value
import itertools
arr = [2,6,8,7,4,2,5,6,2,4,7,8,5,2,7,4,2,5,6,2,4,7,8,5,2,9,3,2,0,1,5,7,2,8,9,3,2,]
def hello(g, data):
data.value += 1
if __name__ == '__main__':
data = Value('i', 0)
func = partial(hello, data)
p = Pool(processes=1)
p.map(hello,itertools.izip(arr,itertools.repeat(data)))
print data.value
Here is the runtime error i'm getting:
RuntimeError: Synchronized objects should only be shared between processes through inheritance
Does anyone know what I'm doing wrong?