Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!newsfeed.xs4all.nl!newsfeed3a.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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'example:': 0.03; 'say,': 0.05; 'tree': 0.05; '(so': 0.07; 'intermediate': 0.07; 'method.': 0.07; 'back.': 0.09; 'explanation': 0.09; 'function,': 0.09; 'imply': 0.09; 'occasionally': 0.09; 'to)': 0.09; 'cc:addr:python- list': 0.11; 'gui': 0.12; 'stored': 0.12; '"is': 0.16; 'cleaner': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ideally,': 0.16; 'implies': 0.16; 'non-trivial': 0.16; 'ought': 0.16; 'sources,': 0.16; 'subclass': 0.16; 'subclassing': 0.16; 'subject:sub': 0.16; 'wording': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'bit': 0.19; 'trying': 0.19; 'passing': 0.19; 'willingness': 0.19; 'coding': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'simpler': 0.24; 'helpful': 0.24; 'question': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'handling': 0.26; 'push': 0.26; 'pass': 0.26; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "we'd": 0.29; 'generally': 0.29; 'involving': 0.30; 'skip:g 30': 0.30; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; 'asked': 0.31; 'code': 0.31; 'easier': 0.31; 'reply.': 0.31; '(perhaps': 0.31; '25,': 0.31; 'delayed': 0.31; 'helpful.': 0.31; 'this.': 0.32; 'probably': 0.32; 'handled': 0.32; "we're": 0.32; 'run': 0.32; 'another': 0.32; 'style': 0.33; 'trouble': 0.34; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; "can't": 0.35; 'info': 0.35; 'advice': 0.35; 'common': 0.35; 'connection': 0.35; 'offered': 0.35; 'no,': 0.35; 'operations': 0.35; 'requirement': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'real-time': 0.36; 'doing': 0.36; 'thanks': 0.36; 'effort': 0.37; 'wrong': 0.37; 'so,': 0.37; 'turn': 0.37; 'step': 0.37; 'being': 0.38; 'sometimes': 0.38; 'thank': 0.38; 'easiest': 0.38; 'process,': 0.38; 'question,': 0.38; 'pm,': 0.38; 'rather': 0.38; 'launch': 0.39; 'enough': 0.39; 'how': 0.40; 'even': 0.60; 'read': 0.60; 'worry': 0.60; 'areas': 0.61; 'new': 0.61; 'simply': 0.61; "you're": 0.61; 'further': 0.61; 'back': 0.62; 'name': 0.63; 'real': 0.63; 'such': 0.63; 'networking': 0.64; 'more': 0.64; 'forward': 0.65; 'management': 0.65; 'within': 0.65; 'reply': 0.66; 'side': 0.67; 'believe': 0.68; 'mar': 0.68; 'potentially': 0.81; '"can': 0.84; 'all;': 0.84; 'fast,': 0.84; 'heh.': 0.84; 'lan.': 0.84; 'technically': 0.84; 'technique.': 0.84; 'absolutely': 0.87; 'approach.': 0.91; 'to:none': 0.92; 'reply,': 0.93; 'connection,': 0.95 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:cc :content-type:content-transfer-encoding; bh=yLxbqptZ8RPDcIW+UxHRQmFI9UeHwL6/7E5cKdOZy6g=; b=GRMD4iAIiroix/HlFn27WOO0jEA6wzJdcsw4Ee0Ip4gQesMwuB195QxZsbEz3VRXVi murnp2r/AUrlXtYyGltvAZ/QDhfV1NPWwwSc9SyPh1IHpUCUMK3sUYkQwTOXKmvghA5W oB8P5SsQwNm6N2V+CqpgNUez+huZRwohftSTOJuHtCeRCs9DcHPOeNbrmyP5fK9RsOGV vhxlOipxv+Oe+eEwcp9DesxvaPcOJMPxs1ukXNyKpaCk5p2qRBGSepRPxd05FeW+OsPA L7qjxosv0a/WLAe6iObosD/PEc1pdAuMvSGt1DdfuirUNMs7VoOViXOV3mWGWuzUGiPJ 8Ziw== MIME-Version: 1.0 X-Received: by 10.68.235.6 with SMTP id ui6mr74029581pbc.45.1395719086122; Mon, 24 Mar 2014 20:44:46 -0700 (PDT) In-Reply-To: <80cf8fb7-d0c5-43a9-bc6f-c61ce6214f98@googlegroups.com> References: <80cf8fb7-d0c5-43a9-bc6f-c61ce6214f98@googlegroups.com> Date: Tue, 25 Mar 2014 14:44:46 +1100 Subject: Re: advice on sub-classing multiprocessing.Process and multiprocessing.BaseManager From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395719089 news.xs4all.nl 2875 [2001:888:2000:d::a6]:42492 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68943 On Tue, Mar 25, 2014 at 2:27 PM, wrote: > Thanks for the reply. I find that appreciation is greatly (perhaps infin= itely) delayed whenever I reply "X is probably not what you want to do" wit= hout further explanation to a question of "can I get some advice on how to = do X?". So, I do thank you for your willingness to reply, even such a guara= nteed-to-be-under-appreciated reply. > Heh. I do see that side of it, but the problem is that sometimes a question will be asked that implies a completely wrong approach. Take this example: "I'm having trouble passing a global variable to a function, how can I do i= t?" This exact question came up recently (I may have the wording wrong), and some of the solutions offered were horrendously convoluted messes involving passing the name of a global to the function which then used 'exec' or 'eval'. While technically that answers the question, it's much more helpful to take a step back - no, let's take a step forward - now another step back - and we're cha-cha'ing! - well, unless you're a real genius, just take the step back, and look at what you're actually trying to achieve. I wasn't trying to imply that you absolutely ought to use a single process, but more that the exact reasons for not using one process are significant in your style of coding the multi-process method. > There are indeed operations that can't be handled with a single process, = such as simultaneously using multiple cores. This is why we want to use mu= ltiprocessing instead of (or, in addition to) threading. We're trying to d= o real-time collection of scientific data from a variety of data sources, g= enerally within a LAN. The data can get largish and fast, and intermediate = processing occasionally requires non-trivial computation time. So being ab= le to launch worker processes that can run independently on separate cores = would be very helpful. Ideally, we'd like to let sub-processes make calls = to the control system too, say, read new data. > > I wasn't really asking "is multiprocessing appropriate?" but whether ther= e was a cleaner way to subclass multiprocessing.BaseManager() to use a subc= lass of Process(). I can believe the answer is No, but thought I'd ask. > I've never subclassed BaseManager like this. It might be simpler to spin off one or more workers and not have them do any network communication at all; that way, you don't need to worry about the cache. Set up a process tree with one at the top doing only networking and process management (so it's always fast), and then use a multiprocessing.Queue or somesuch to pass info to a subprocess and back. Then your global connection state is all stored within the top process, and none of the others need care about it. You might have a bit of extra effort to pass info back to the parent rather than simply writing it to the connection, but that's a common requirement in other areas (eg GUI handling - it's common to push all GUI manipulation onto the main thread), so it's a common enough model. But if subclassing and tweaking is the easiest way, and if you don't mind your solution being potentially fragile (which subclassing like that is), then you could look into monkey-patching Process. Inject your code into it and then use the original. It's not perfect, but it may turn out easier than the "subclass everything" technique. ChrisA