Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.024 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; '__name__': 0.09; 'snippet': 0.09; 'subject:process': 0.09; 'def': 0.12; '#this': 0.16; "'__main__':": 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'inputs': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'subject:skip:m 10': 0.16; 'sys.exit(0)': 0.16; 'tried:': 0.16; 'try?': 0.16; 'typo': 0.16; 'wrote:': 0.18; 'solution.': 0.20; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'code': 0.31; 'prints': 0.31; 'basic': 0.35; 'problem.': 0.35; 'there': 0.35; 'detail': 0.37; 'thank': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'solve': 0.60; 'further': 0.61; 'provide': 0.64; 'more': 0.64; 'different': 0.65; 'hang': 0.67; 'header:Reply-To:1': 0.67; 'answer.': 0.68; 'reply-to:no real name:2**0': 0.71; 'evaluate': 0.72; 'reply- to:addr:python.org': 0.84; 'subject:answer': 0.95 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=bKAvfpOZ c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=2LCq-pQfA8cA:10 a=Swc_Nzi1r10A:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=3rc6q643dMAA:10 a=tUwZYhuKcyc9c3w1CTQA:9 a=wPNLvfGTeEIA:10 X-AUTH: mrabarnett:2500 Date: Sat, 02 Nov 2013 02:52:40 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: multiprocessing: child process race to answer References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383360757 news.xs4all.nl 15884 [2001:888:2000:d::a6]:56138 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:58312 On 02/11/2013 02:35, 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 > Did you actually mean "pool.terminate", or is that a typo for "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 >