How can I access a shared dictionary with multiprocessing?
<p>I think I am following the python documentation correctly but I am having trouble getting the result I am looking for. I basically have a list of numbers, that are being passed to a function of nested for loops and the output is saved in a dictionary.</p>

<p>Here's the code:</p>

<pre><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))

    # Mark pool as closed -- no more tasks can be added.
    pool.close()

    # Wait for tasks to exit
    pool.join()

    # Output results
    print d
</code></pre>

<p>Here's the expected result:</p>

<pre><code>{1: 9801, 2: 9801, 3: 9801, 10: 9801}
</code></pre>

<p>Any suggestions of what I'm doing wrong? Also, I haven't convinced myself that shared resources are the best approach(thinking of using a database to maintain state) so if my approach is completely flawed or there's a better way to do this in python please let me know.</p>
