Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1a.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'causing': 0.04; 'subject:Python': 0.06; 'suppose': 0.07; '__name__': 0.09; 'imported': 0.09; 'will,': 0.09; 'runs': 0.10; 'subject:Help': 0.11; 'python': 0.11; 'def': 0.12; '2.7': 0.14; "'__main__':": 0.16; 'executed.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'once.': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'spawn': 0.16; 'turn,': 0.16; 'thursday,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'written': 0.21; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'module,': 0.24; 'header:In-Reply-To:1': 0.27; 'code': 0.31; "skip:' 10": 0.31; '13,': 0.31; 'run': 0.32; 'another': 0.32; 'trouble': 0.34; 'subject:with': 0.35; 'received:84': 0.35; 'but': 0.35; 'module.': 0.36; 'doing': 0.36; 'thanks': 0.36; 'process,': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'called': 0.40; 'how': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'new': 0.61; "you've": 0.63; 'name': 0.63; 'different': 0.65; 'ending': 0.78; 'spawned': 0.84; 'subject:skip:M 10': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=ZZGTN6lA c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=aoAcgTy3oA8A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=XoPrOVCObVI__weidt4A:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett:2500 Date: Thu, 13 Nov 2014 18:45:35 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Help with Python Multiprocessing References: <91fd5810-6a2a-46d8-8d1e-b68afced3987@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list 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: 56 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415904344 news.xs4all.nl 2942 [2001:888:2000:d::a6]:59550 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80696 On 2014-11-13 18:10, Anurag wrote: > On Thursday, November 13, 2014 1:07:56 PM UTC-5, Anurag wrote: >> I am having trouble understanding the Multiprocessing module. >> I need to run three different files 'Worker1' , 'Worker2', 'Worker3' all at once. Currently I am doing this : >> >> from multiprocessing import Process >> >> import Worker1.py >> import Worker2.py >> import Worker3.py >> >> >> >> p1 = Process(target=Worker1.py) >> p1.start() >> p2 = Process(target=Worker2.py) >> p2.start() >> p3 = Process(target=Worker3.py) >> p3.start() >> >> But this will only start the 'Worker1'. How do I execute all the three files at once? >> >> Thanks > > I am using Python 2.7 and each of my 'Worker' has a never ending loop that runs continuously. > The documentation has this example: from multiprocessing import Process def f(name): print 'hello', name if __name__ == '__main__': p = Process(target=f, args=('bob',)) p.start() p.join() Suppose this is in a module called 'example.py'. When 'example.py' is run as the main module, it executes: p = Process(target=f, args=('bob',)) p.start() The multiprocessing module will _import_ 'example.py' in a new process, and because it's only imported (and not run as a main module), that code won't be executed. The multiprocessing module will then call the 'f' function. The way you've written your module, it'll spawn a new process even when it's only imported, causing the spawned process to spawn another process, which will, in turn, spawn another...