Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Noah Newsgroups: comp.lang.python Subject: multiprocessing not quite working Date: Tue, 24 May 2016 15:17:02 -0700 Lines: 62 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de R4BBZrvr0LJEKSdNSMNCRASpylxZqX0/fQJzsTIzlUdw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'skip:[ 20': 0.03; '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; 'here"': 0.16; 'main():': 0.16; 'processes.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:z 30': 0.16; 'stringio()': 0.16; 'skip:{ 20': 0.18; 'cheers': 0.24; 'url:edu': 0.24; 'header:User-Agent:1': 0.26; 'define': 0.27; "skip:' 10": 0.28; 'issues.': 0.29; 'queue': 0.29; 'array': 0.29; 'print': 0.30; 'code': 0.30; 'skip:[ 10': 0.31; 'returned': 0.32; 'getting': 0.33; 'run': 0.33; 'url:06': 0.33; 'previous': 0.34; 'list': 0.34; 'comment': 0.35; 'skip:{ 10': 0.36; 'to:addr:python- list': 0.36; 'two': 0.37; 'skip:o 20': 0.38; 'hi,': 0.38; 'to:addr:python.org': 0.40; 'url:2014': 0.66; 'here': 0.66; 'results': 0.66; 'therefore': 0.67; 'completed': 0.69; 'received:38': 0.81 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: Xref: csiph.com comp.lang.python:109091 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) Cheers