Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109093
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: multiprocessing not quite working |
| Date | Wed, 25 May 2016 00:39:38 +0100 |
| Lines | 83 |
| Message-ID | <mailman.71.1464133185.20402.python-list@python.org> (permalink) |
| References | <f803eff5-786e-703f-4625-69f5e64c6a6e@enabled.com> <5ec4b860-e38d-55f4-1d54-d1f944bfeb33@mrabarnett.plus.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de Kj4doDWlviVmOIkptn4YxQFsoLrnHCWaHcFLraPT0jTg== |
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'skip:[ 20': 0.03; '"""': 0.05; '(python': 0.05; 'tries': 0.05; 'exit': 0.07; 'subject:skip:m 10': 0.09; 'example:': 0.10; 'subject:not': 0.11; 'output': 0.13; 'def': 0.13; '"."': 0.16; '"got': 0.16; 'appends': 0.16; 'consume': 0.16; 'deadlock': 0.16; 'flushed': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'here"': 0.16; 'main():': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'pipes': 0.16; 'processes.': 0.16; 'received:192.168.1.4': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'similarly,': 0.16; 'skip:j 30': 0.16; 'skip:z 30': 0.16; 'stringio()': 0.16; 'wrote:': 0.16; 'skip:{ 20': 0.18; 'issue.': 0.20; 'terminate': 0.22; 'trying': 0.22; 'programming': 0.22; 'url:edu': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'define': 0.27; "skip:' 10": 0.28; 'issues.': 0.29; 'joining': 0.29; 'queue': 0.29; 'array': 0.29; 'print': 0.30; 'code': 0.30; 'skip:[ 10': 0.31; 'says': 0.32; 'returned': 0.32; 'getting': 0.33; 'run': 0.33; 'url:06': 0.33; 'previous': 0.34; 'list': 0.34; 'comment': 0.35; 'should': 0.36; 'created': 0.36; '(and': 0.36; 'child': 0.36; 'skip:{ 10': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'skip:o 20': 0.38; 'hi,': 0.38; 'means': 0.39; 'sure': 0.39; 'does': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'hang': 0.60; 'above,': 0.63; 'url:2014': 0.66; 'here': 0.66; 'results': 0.66; 'therefore': 0.67; 'completed': 0.69; 'children.': 0.76; '*if': 0.84; 'guidelines.': 0.84 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=K//fZHiI c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=IkcTkHD0fZMA:10 a=G1H9XeTJAAAA:8 a=Corov10P02hWNBMcYhUA:9 a=QEXdDO2ut3YA:10 a=g6OYqls-1w_fQhGz_oZa:22 |
| X-AUTH | mrabarnett@:2500 |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 |
| In-Reply-To | <f803eff5-786e-703f-4625-69f5e64c6a6e@enabled.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| 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> |
| X-Mailman-Original-Message-ID | <5ec4b860-e38d-55f4-1d54-d1f944bfeb33@mrabarnett.plus.com> |
| X-Mailman-Original-References | <f803eff5-786e-703f-4625-69f5e64c6a6e@enabled.com> |
| Xref | csiph.com comp.lang.python:109093 |
Show key headers only | View raw
On 2016-05-24 23:17, Noah wrote:
>
> Hi,
>
> I am using this example:
> http://spartanideas.msu.edu/2014/06/20/an-introduction-to-parallel-programming-using-pythons-multiprocessing-module/
>
> I am sending and receiving communication from the worker processes.
>
> Two issues. the join is only getting to the process and waiting.
> When I comment out the .join() process the output.get() appends the
> previous process and therefore the returned output keeps getting longer
> and longer after each process returns its output.
>
> hostnames is an array of hostnames.
>
> here is my code from main():
>
> # Define an output queue
> output = mp.Queue()
>
> # Setup a list of processes that we want to run
> processes = [mp.Process(target=worker, args=(hostnames[x], output))
> for x in range(len(hostnames))]
>
> # Run processes
> for p in processes:
> print "start: {}".format(p)
> p.start()
>
> time.sleep(6)
> print "processes: {}".format(processes)
>
> # Exit the completed processes
> '''for p in processes:
> print "join: {}".format(p)
> p.join()'''
>
> print "got here"
> # Get process results from the output queue
> # results = [output.get() for p in processes]
>
> io = StringIO()
> count = 0
> for p in processes:
> found_output = output.get()
> print "returned {}".format(p)
> io.write (found_output)
> zipArchive.writestr(hostnames[count] + "." +
> content['sitename'] + '.config.txt', io.getvalue())
> count = count + 1
> io.close()
>
>
> def worker(hostname, output):
> .
> .
> .
> output.put(template_output)
>
>
It says in the docs (Python 2.7, 16.6.2.2. Pipes and Queues):
"""Warning
As mentioned above, if a child process has put items on a queue (and it
has not used JoinableQueue.cancel_join_thread), then that process will
not terminate until all buffered items have been flushed to the pipe.
This means that *if you try joining that process you may get a deadlock
unless you are sure that all items which have been put on the queue have
been consumed*. Similarly, if the child process is non-daemonic then the
parent process may hang on exit when it tries to join all its
non-daemonic children.
Note that a queue created using a manager does not have this issue. See
Programming guidelines.
"""
(Asterisks added to highlight.)
You should try to consume the output from a process before trying to
join it (or, at least, join it without a timeout).
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: multiprocessing not quite working MRAB <python@mrabarnett.plus.com> - 2016-05-25 00:39 +0100
csiph-web