'Update global variable with Pool() executions
Pretty new to multiprocessing and global variables, need to update value x with every pool execution. Final result will be 65 (5+10+20+30). Any thoughts?
from multiprocessing import Pool
x = 5
def modify(part):
global x
x += part
if __name__ == '__main__':
parts = [10, 20, 30]
with Pool(3) as p:
p.map(modify, parts)
print(x)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|