Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #58324
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <wrw@mac.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.010 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'mrab': 0.05; '__name__': 0.09; 'friday,': 0.09; 'snippet': 0.09; 'subject:process': 0.09; 'whichever': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '#this': 0.16; "'__main__':": 0.16; 'check.': 0.16; 'finds': 0.16; 'for,': 0.16; 'inputs': 0.16; 'received:mac.com': 0.16; 'simplest': 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; 'received:10.0.1': 0.19; 'solution.': 0.20; 'written': 0.21; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**1': 0.23; 'creating': 0.23; 'looks': 0.24; 'cc:no real name:2**0': 0.24; 'defined': 0.27; 'correct': 0.29; 'am,': 0.29; 'url:mailman': 0.30; 'code': 0.31; 'os,': 0.31; 'prints': 0.31; 'file': 0.32; 'url:python': 0.33; 'maybe': 0.34; 'basic': 0.35; "can't": 0.35; 'problem.': 0.35; 'something': 0.35; 'there': 0.35; 'accessible': 0.36; 'url:listinfo': 0.36; 'charset:us- ascii': 0.36; 'received:10.0': 0.36; 'url:org': 0.36; 'detail': 0.37; 'so,': 0.37; 'received:10': 0.37; 'thank': 0.38; 'nov': 0.38; 'received:17': 0.38; 'anything': 0.39; 'bill': 0.39; 'sure': 0.39; 'url:mail': 0.40; 'solve': 0.60; 'simple': 0.61; 'further': 0.61; 'provide': 0.64; 'more': 0.64; 'different': 0.65; 'situation': 0.65; 'to:addr:gmail.com': 0.65; 'hang': 0.67; 'answer.': 0.68; 'periodically': 0.68; 'evaluate': 0.72; 'header :In-reply-to:1': 0.84; 'wakes': 0.84; '2013,': 0.91; 'subject:answer': 0.95; '2013': 0.98 |
| X-Proofpoint-Virus-Version | vendor=fsecure engine=2.50.10432:5.10.8794,1.0.431,0.0.0000 definitions=2013-11-02_01:2013-11-02,2013-11-02,1970-01-01 signatures=0 |
| X-Proofpoint-Spam-Details | rule=notspam policy=default score=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1308280000 definitions=main-1311020072 |
| Content-type | text/plain; charset=us-ascii |
| MIME-version | 1.0 (Mac OS X Mail 6.6 \(1510\)) |
| Subject | Re: multiprocessing: child process race to answer |
| From | William Ray Wing <wrw@mac.com> |
| In-reply-to | <e92096bb-f571-4a4f-9dcc-604e4cce4125@googlegroups.com> |
| Date | Sat, 02 Nov 2013 08:17:08 -0400 |
| Content-transfer-encoding | quoted-printable |
| References | <f71ef852-81ee-4ce6-beaa-17a881ed6d16@googlegroups.com> <mailman.1946.1383360757.18130.python-list@python.org> <e92096bb-f571-4a4f-9dcc-604e4cce4125@googlegroups.com> |
| To | smhall05 <smhall05@gmail.com> |
| X-Mailer | Apple Mail (2.1510) |
| Cc | python-list@python.org, William Ray Wing <wrw@mac.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.1950.1383394638.18130.python-list@python.org> (permalink) |
| Lines | 59 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1383394638 news.xs4all.nl 15871 [2001:888:2000:d::a6]:58557 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:58324 |
Show key headers only | View raw
On Nov 2, 2013, at 1:03 AM, smhall05 <smhall05@gmail.com> wrote: > On Friday, November 1, 2013 10:52:40 PM UTC-4, MRAB wrote: >> 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 >>> > > I am not sure to be honest, however it turns out that I can't use pool.terminate() because pool is defined in main and not accessible under my def in which I check for the correct answer. > -- > https://mail.python.org/mailman/listinfo/python-list So, the simplest solution to that situation is to have whichever subprocess that finds the correct answer set a flag which the calling process can check. Depending on your OS, that flag can be anything from setting a lock to something as simple as creating a file which the calling process periodically wakes up and looks for, maybe just a file in which the subprocess has written the answer. Bill
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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