Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'scripts': 0.03; 'preference': 0.07; 'subject:script': 0.09; 'python': 0.11; 'cons': 0.16; 'fine.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'jython,': 0.16; 'processes.': 0.16; 'referencing': 0.16; 'script?': 0.16; 'subject:versus': 0.16; 'variables,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'separate': 0.22; 'module,': 0.24; 'looks': 0.24; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; '(like': 0.30; 'message- id:@mail.gmail.com': 0.30; 'purely': 0.31; "they'll": 0.31; 'run': 0.32; 'running': 0.33; 'fri,': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'easily': 0.37; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'matter': 0.61; 'simply': 0.61; "you're": 0.61; 'details': 0.65; 'between': 0.67; 'suits': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=CrFNc1EK1Em5IzjiZWiqqG93h43fHgETeRIBjpmlP18=; b=ih3pGSOzo7m/5MwJYoP3L51dF0aPWC9Hq0+nmOhebnn/LiDrO437hC1QG/fK6BSNlE 0l3QhL5643Gc+efVrhRRgFWgELcmeHyxsH6lA6d2tihifN/vFGK6E6YiD6ybootFHe48 7MklF0xWIZZlwLlXx/9CEOmS4bsxWlpvlgmgmLaWQ0m+Run97mfcLP4BzYNETB6mocu/ vm2DEQEdavvbsAlpU2ZULMTGYH6OCy0PEEiLAQyFy/sarxbM8aLERooR8Dmflh6u8v8y mtLX7BDZv3PGWOytgrBVvHITRuXQxR351v4dUyPLsPmSt8Ng+A9/Svgcua3Cm6ea6iVP zShw== MIME-Version: 1.0 X-Received: by 10.68.192.195 with SMTP id hi3mr9631437pbc.18.1380818524727; Thu, 03 Oct 2013 09:42:04 -0700 (PDT) In-Reply-To: References: Date: Fri, 4 Oct 2013 02:42:04 +1000 Subject: Re: Multiple scripts versus single multi-threaded script From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380818535 news.xs4all.nl 16003 [2001:888:2000:d::a6]:42048 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:55422 On Fri, Oct 4, 2013 at 2:01 AM, JL wrote: > What is the difference between running multiple python scripts and a single multi-threaded script? May I know what are the pros and cons of each approach? Right now, my preference is to run multiple separate python scripts because it is simpler. (Caveat: The below is based on CPython. If you're using IronPython, Jython, or some other implementation, some details may be a little different.) Multiple threads can share state easily by simply referencing each other's variables, but the cost of that is that they'll never actually execute simultaneously. If you want your scripts to run in parallel on multiple CPUs/cores, you need multiple processes. But if you're doing something I/O bound (like servicing sockets), threads work just fine. As to using separate scripts versus the multiprocessing module, that's purely a matter of what looks cleanest. Do whatever suits your code. ChrisA