I am using multiprocessing to speed up (dramatically speeds up by the way) my program but it is crucial that a certain global variable gets updated. The global variable is only used in the same class that uses multiprocessing so maybe there is a workaround for this variable not getting updated. Here is the code for a test I am using to try and solve this issue:
aylmao = []
def test(a):
aylmao.append(a)
if __name__ == '__main__':
d = [1,2,3,4,5,6,7,8,9]
pool = Pool(cpu_count() * 2)
pool.map(test, d)
print(aylmao)
So in my main code I have a function that is called using pool.map and it updates this global variable. But at the end of the program it pickles the information in the global variable so that I can continue where my program left off from. However using pool.map makes it so that this global variable is empty by the time of printing and I am unsure how to work around that. Any help is extremely appreciated as using pool.map vastly increases the speed of my program.
if i instead run the code like this:
aylmao = []
def test(a):
aylmao.append(a)
if __name__ == '__main__':
d = [1,2,3,4,5,6,7,8,9]
for i in d:
test(i)
print(aylmao)
the output is [1,2,3,4,5,6,7,8,9] which is exactly what I want. but when using pool.map(test,d) the output is []. How can I make sure the global variable is being updated when using pool.map(test,d)