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


Groups > comp.lang.python > #58386

Re: multiprocessing: child process race to answer

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; '__name__': 0.09; 'friday,': 0.09; 'lawrence': 0.09; 'prevents': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'snippet': 0.09; 'subject:process': 0.09; 'tismer': 0.09; 'python': 0.11; 'def': 0.12; '#this': 0.16; "'__main__':": 0.16; 'inputs': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'spacing': 0.16; 'subject:skip:m 10': 0.16; 'sys.exit(0)': 0.16; 'tried:': 0.16; 'try?': 0.16; 'language': 0.16; 'wrote:': 0.18; 'module': 0.19; 'solution.': 0.20; 'programming': 0.22; 'import': 0.22; 'print': 0.22; 'header :User-Agent:1': 0.23; 'url:moin': 0.24; 'second': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'code': 0.31; 'url:wiki': 0.31; 'prints': 0.31; 'url:python': 0.33; 'could': 0.34; 'basic': 0.35; 'problem.': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; 'thanks': 0.36; 'url:org': 0.36; 'detail': 0.37; 'christian': 0.38; 'thank': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'read': 0.60; 'above,': 0.60; 'solve': 0.60; 'url:3': 0.61; 'world.': 0.61; 'further': 0.61; 'email addr:gmail.com': 0.63; 'provide': 0.64; 'more': 0.64; 'different': 0.65; 'between': 0.67; 'hang': 0.67; 'answer.': 0.68; 'evaluate': 0.72; 'exchanging': 0.91; 'subject:answer': 0.95; '2013': 0.98
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: multiprocessing: child process race to answer
Date Sun, 03 Nov 2013 10:24:54 +0000
References <f71ef852-81ee-4ce6-beaa-17a881ed6d16@googlegroups.com> <0e33c77e-3489-44ac-ba5c-2507adc5e827@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-78-147-179-131.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.0
In-Reply-To <0e33c77e-3489-44ac-ba5c-2507adc5e827@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1976.1383474301.18130.python-list@python.org> (permalink)
Lines 65
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1383474301 news.xs4all.nl 15997 [2001:888:2000:d::a6]:49385
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:58386

Show key headers only | View raw


On 03/11/2013 10:10, cappleman@gmail.com wrote:
> On Friday, November 1, 2013 10:35:47 PM UTC-4, smhall05 wrote:
>> I am using a basic multiprocessing snippet I found:
>>
>>
>>
>> #-----------------------------------------------------
>>
>> from multiprocessing import Pool
>>
>>
>>
>> def  f(x):
>>
>>      return x*x
>>
>>
>>
>> if __name__ == '__main__':
>>
>>      pool = Pool(processes=4)              # start 4 worker processes
>>
>>      result = pool.apply_async(f, [10])    # evaluate "f(10)" asynchronously
>>
>>      print result.get(timeout=1)
>>
>>      print pool.map(f, range(10))          # prints "[0, 1, 4,..., 81]"
>>
>> #---------------------------------------------------------
>>
>>
>>
>> I am using this code to have each process go off and solve the same problem, just with different inputs to the problem. I need to be able to kill all processes once 1 of n processes has come up with the solution. There will only be one answer.
>>
>>
>>
>> I have tried:
>>
>>
>>
>> sys.exit(0) #this causes the program to hang
>>
>> pool.close()
>>
>> pool.terminate
>>
>>
>>
>> These still allow further processing before the program terminates. What else can I try? I am not able to share the exact code at this time. I can provide more detail if I am unclear. Thank you
>
> You could take a look at the Mutiprocessing module capabilities for exchanging objects between processes:
>
> http://docs.python.org/3.3/library/multiprocessing.html#exchanging-objects-between-processes
>

Would you please read and action this as it prevents the double line 
spacing that you can observe above, thanks 
https://wiki.python.org/moin/GoogleGroupsPython

-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Thread

multiprocessing: child process race to answer smhall05 <smhall05@gmail.com> - 2013-11-01 19:35 -0700
  Re: multiprocessing: child process race to answer MRAB <python@mrabarnett.plus.com> - 2013-11-02 02:52 +0000
    Re: multiprocessing: child process race to answer smhall05 <smhall05@gmail.com> - 2013-11-01 22:03 -0700
      Re: multiprocessing: child process race to answer William Ray Wing <wrw@mac.com> - 2013-11-02 08:17 -0400
      Re: multiprocessing: child process race to answer Sherard Hall <smhall05@gmail.com> - 2013-11-02 11:44 -0400
      Re: multiprocessing: child process race to answer (forgot to Cc: the list) William Ray Wing <wrw@mac.com> - 2013-11-02 23:07 -0400
  Re: multiprocessing: child process race to answer cappleman@gmail.com - 2013-11-03 02:10 -0800
    Re: multiprocessing: child process race to answer Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-03 10:24 +0000

csiph-web