<br>I'm afraid I've not heard of a way of putting more complex objects into shared memory with multiprocessing.  That is, not without using a queue along the lines of <a href="http://docs.python.org/library/multiprocessing.html#exchanging-objects-between-processes">http://docs.python.org/library/multiprocessing.html#exchanging-objects-between-processes</a> , which isn't quite the same thing.<br>
<br><div class="gmail_quote">On Thu, Apr 7, 2011 at 5:57 PM, Kerensa McElroy <span dir="ltr"><<a href="mailto:kerensaelise@hotmail.com">kerensaelise@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">




<div>
Hi,<br><br>thanks for your response.<br><br>I checked out multiprocessing.value, however from what I can make out, it works with object of only a very limited type. Is there a way to do this for more complex objects? (In reality, my object is a large multi-dimensional numpy array).<br>
<br>Thanks,<br><font color="#888888"><br>Elsa.<br></font><div class="hm"><br><hr>Date: Wed, 6 Apr 2011 22:20:06 -0700<br>Subject: Re: multiprocessing<br>From: <a href="mailto:drsalists@gmail.com" target="_blank">drsalists@gmail.com</a><br>
To: <a href="mailto:kerensaelise@hotmail.com" target="_blank">kerensaelise@hotmail.com</a><br>CC: <a href="mailto:python-list@python.org" target="_blank">python-list@python.org</a></div><div><div></div><div class="h5"><br>
<br><br><div>On Wed, Apr 6, 2011 at 9:06 PM, elsa <span dir="ltr"><<a>kerensaelise@hotmail.com</a>></span> wrote:<br><blockquote style="padding-left: 1ex;">
Hi guys,<br>
<br>
I want to try out some pooling of processors, but I'm not sure if it<br>
is possible to do what I want to do. Basically, I want to have a<br>
global object, that is updated during the execution of a function, and<br>
I want to be able to run this function several times on parallel<br>
processors. The order in which the function runs doesn't matter, and<br>
the value of the object doesn't matter to the function, but I do want<br>
the processors to take turns 'nicely' when updating the object, so<br>
there are no collisions. Here is an extremely simplified and trivial<br>
example of what I have in mind:<br>
<br>
from multiprocessing import Pool<br>
import random<br>
<br>
p=Pool(4)<br>
myDict={}<br>
<br>
def update(value):<br>
    global myDict<br>
    index=random.random()<br>
    myDict[index]+=value<br>
<br>
total=1000<br>
<br>
p.map(update,range(total))<br>
<br>
<br>
After, I would also like to be able to use several processors to<br>
access the global object (but not modify it). Again, order doesn't<br>
matter:<br>
<br>
p1=Pool(4)<br>
<br>
def getValues(index):<br>
    global myDict<br>
    print myDict[index]<br>
<br>
p1.map(getValues,keys.myDict)<br>
<br>
Is there a way to do this </blockquote></div><br>This should give you a synchronized wrapper around an object in shared memory:<br><br><a>http://docs.python.org/library/multiprocessing.html#multiprocessing.Value</a><br>
<br>                                        </div></div></div>
</blockquote></div><br>