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


Groups > comp.lang.python > #58386

Re: multiprocessing: child process race to answer

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: multiprocessing: child process race to answer
Date 2013-11-03 10:24 +0000
References <f71ef852-81ee-4ce6-beaa-17a881ed6d16@googlegroups.com> <0e33c77e-3489-44ac-ba5c-2507adc5e827@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1976.1383474301.18130.python-list@python.org> (permalink)

Show all headers | 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