Share a list between different processes?
<p>I have the following problem. I have written a function that takes a list as input and creates a dictionary for each element in the list. I then want to append this dictionary to a new list, so I get a list of dictionaries. I am trying to spawn multiple processes for this. My problem here is that I want the different processes to access the list of dictionaries as it is updated by other processes, for example to print something once the has reached a certain length.</p>
<p>My example would be like this:</p>
<pre><code>import multiprocessing

list=['A', 'B', 'C', 'D', 'E', 'F']

def do_stuff(element):
    element_dict={}
    element_dict['name']=element
    new_list=[]
    new_list.append(element_dict)
    if len(new_list)&gt;3:
        print 'list &gt; 3'

###Main###
pool=multiprocessing.Pool(processes=6)
pool.map(do_stuff, list)
pool.close()
</code></pre>
<p>Right now my problem is that each process creates its own <code>new_list</code>. Is there a way to share the list between processes, such that all dictionaries are appended to the same list? Or is the only way to define the <code>new_list</code> outside of the function?</p>