Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2739

multiprocessing

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!f11g2000vbx.googlegroups.com!not-for-mail
From elsa <kerensaelise@hotmail.com>
Newsgroups comp.lang.python
Subject multiprocessing
Date Wed, 6 Apr 2011 21:06:25 -0700 (PDT)
Organization http://groups.google.com
Lines 46
Message-ID <75a6974b-d954-4528-8bbc-9ab7b6b8b80b@f11g2000vbx.googlegroups.com> (permalink)
NNTP-Posting-Host 149.171.173.69
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
X-Trace posting.google.com 1302149185 31161 127.0.0.1 (7 Apr 2011 04:06:25 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Thu, 7 Apr 2011 04:06:25 +0000 (UTC)
Complaints-To groups-abuse@google.com
Injection-Info f11g2000vbx.googlegroups.com; posting-host=149.171.173.69; posting-account=bbteZwoAAACbfxlyOHsZW_iAie62mZX6
User-Agent G2/1.0
X-HTTP-UserAgent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.14) Gecko/20110218 Firefox/3.6.14,gzip(gfe)
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:2739

Show key headers only | View raw


Hi guys,

I want to try out some pooling of processors, but I'm not sure if it
is possible to do what I want to do. Basically, I want to have a
global object, that is updated during the execution of a function, and
I want to be able to run this function several times on parallel
processors. The order in which the function runs doesn't matter, and
the value of the object doesn't matter to the function, but I do want
the processors to take turns 'nicely' when updating the object, so
there are no collisions. Here is an extremely simplified and trivial
example of what I have in mind:

from multiprocessing import Pool
import random

p=Pool(4)
myDict={}

def update(value):
    global myDict
    index=random.random()
    myDict[index]+=value

total=1000

p.map(update,range(total))


After, I would also like to be able to use several processors to
access the global object (but not modify it). Again, order doesn't
matter:

p1=Pool(4)

def getValues(index):
    global myDict
    print myDict[index]

p1.map(getValues,keys.myDict)

Is there a way to do this?

Thanks,

Elsa.

Back to comp.lang.python | Previous | NextNext in thread | Find similar


Thread

multiprocessing elsa <kerensaelise@hotmail.com> - 2011-04-06 21:06 -0700
  Re: multiprocessing Philip Semanchuk <philip@semanchuk.com> - 2011-04-07 21:05 -0400

csiph-web