Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'tutorial': 0.03; 'patterns': 0.04; 'classes,': 0.05; 'importing': 0.05; 'ugly': 0.07; 'statements': 0.09; 'subject:module': 0.09; 'url:github': 0.09; 'wrote': 0.14; 'imo.': 0.16; 'pythonic': 0.16; 'subclass': 0.16; 'subject:skip:m 10': 0.16; 'url:py': 0.16; 'appropriate': 0.16; 'module': 0.19; 'trying': 0.19; 'written': 0.21; 'code,': 0.22; 'example': 0.22; 'import': 0.22; "shouldn't": 0.24; 'sort': 0.25; 'certain': 0.27; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(my': 0.31; 'go.': 0.31; 'piece': 0.31; 'them?': 0.31; 'with,': 0.31; 'figure': 0.32; 'run': 0.32; 'community': 0.33; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'curious': 0.36; 'subject:?': 0.36; 'should': 0.36; 'process,': 0.38; 'tools,': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'most': 0.60; 'skip:n 10': 0.64; 'here': 0.66; 'url:master': 0.84; 'hate': 0.91; 'incredibly': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Qz9xaN+cjEnNCDYDRFYaOeAneEITK+KPqfwgxw5UM6M=; b=qDeaBLSYSTYjcl/UmKDeMPUSh62jrXiRxJXrT1yB9JOa+e1Ms6jsLducH0bIm2pPmU XhAkRFtoI7b5H0FOEvO8bCLDGKqYXx6uFZUvpPCpL+HRI+8/BArgc2u4Yq8vrbXalInP v8kIERPej9PIZvU8JXO1geZASR4t8OjQpFOrj1dYURs1XW5werpyGIqBzSFht++DV8o9 +cqzcLZk0ZfLYIURso1bFmtrZX9ZYZcVAE1AiNGThfBzoYrNfbJYXuTFGWBz9Ujj+dhw jMDTeQixSqiLpfGPo46vnMTCxv8B29p90e6w3lQFY7b5DPbUIr901Xl7xHwfuai9S/HD utMw== MIME-Version: 1.0 X-Received: by 10.236.30.233 with SMTP id k69mr10823542yha.123.1424715966398; Mon, 23 Feb 2015 10:26:06 -0800 (PST) Date: Mon, 23 Feb 2015 10:26:06 -0800 Subject: multiprocessing module best practices? From: Christian Calderon To: python-list@python.org Content-Type: multipart/alternative; boundary=001a11c20276154966050fc589b0 X-Mailman-Approved-At: Mon, 23 Feb 2015 19:40:30 +0100 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: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424716831 news.xs4all.nl 2844 [2001:888:2000:d::a6]:40468 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86252 --001a11c20276154966050fc589b0 Content-Type: text/plain; charset=UTF-8 Is there a good blog or tutorial on when it is most appropriate to use the Process vs Pool classes, and when you should subclass either of them? I have written a few programs using these tools, and each time I have to sort of make up my own design patterns as I go. I want to know what the community thinks is the most pythonic use of the multiprocessing module (I could just subclass Process every single time, why shouldn't I?) I'm also curious about when I should be importing modules in the main module to use in a Process, and when I should import the module inside the run method/target function. Certain modules just won't work unless I import it in the Process; I hate having a ton of import statements inside my functions, but I also hate having to guess-and-check just to figure out which modules I can import outside the function. And it is just kinda ugly to have import statements at multiple parts of the same piece of code, IMO. Here is an example of something I wrote that feels kinda funky (my excuse is that the code-base I was working with was incredibly funky to begin with, and I was trying to make a small corner of it nicer/actually work.): https://github.com/zack-bitcoin/augur-core/blob/master/database.py --001a11c20276154966050fc589b0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Is there a good blog or tutorial on when it is most approp= riate to use the Process vs Pool classes, and when you should subclass eith= er of them? I have written a few programs using these tools, and each time = I have to sort of make up my own design patterns as I go. I want to know wh= at the community thinks is the most pythonic use of the multiprocessing mod= ule (I could just subclass Process every single time, why shouldn't I?)=

I'm also curious about when I should be importing m= odules in the main module to use in a Process, and when I should import the= module inside the run method/target function. Certain modules just won'= ;t work unless I import it in the Process; I hate having a ton of import st= atements inside my functions, but I also hate having to guess-and-check jus= t to figure out which modules I can import outside the function. And it is = just kinda ugly to have import statements at multiple parts of the same pie= ce of code, IMO.

Here is an example of something I wrote that feels = kinda funky (my excuse is that the code-base I was working with was incredi= bly funky to begin with, and I was trying to make a small corner of it nice= r/actually work.):
--001a11c20276154966050fc589b0--