I think I am following python documentation correctly, but it's hard for me to get the result I'm looking for. I basically have a list of numbers that are passed to the function of nested loops, and the output is stored in a dictionary.
Here is the code:
from multiprocessing import Pool, Manager list = [1,2,3,10] dictionary = {} def test(x, dictionary): for xx in range(100): for xxx in range(100): dictionary[x]=xx*xxx if __name__ == '__main__': pool = Pool(processes=4) mgr = Manager() d = mgr.dict() for N in list: pool.apply_async(test, (N, d))
Here's the expected result:
{1: 9801, 2: 9801, 3: 9801, 10: 9801}
Any suggestions on what I'm doing wrong? Also, I have not convinced myself that sharing resources is a better approach (thinking about using a database to maintain state), so if my approach is completely messed up or is there a better way to do this in python, please let me know.
source share