Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Cameron Simpson Newsgroups: comp.lang.python Subject: Re: Bi-directional sub-process communication Date: Tue, 24 Nov 2015 08:45:16 +1100 Lines: 28 Message-ID: References: <5A3A00A6-CFD2-42FC-9C87-6F8C6861F775@ravnalaska.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed X-Trace: news.uni-berlin.de pYtsMVJmPK+6/pEPP6FusQ9n3u1EnkLOmi+8/pE4mBlw== 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; 'subject:skip:c 10': 0.07; 'cc:addr:python-list': 0.09; '(actually': 0.09; 'handler.': 0.09; 'subject:process': 0.09; 'thread': 0.10; ':-)': 0.12; '23,': 0.16; '>on': 0.16; '>to': 0.16; 'cc:name:python': 0.16; 'concurrency': 0.16; 'concurrency,': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:io': 0.16; 'received:optusnet.com.au': 0.16; 'received:psf.io': 0.16; 'received:syd.optusnet.com.au': 0.16; 'simpson': 0.16; 'subject:sub': 0.16; 'threads': 0.16; 'wake': 0.16; 'wrote:': 0.16; 'passes': 0.18; 'cc:addr:python.org': 0.20; 'cc:2**1': 0.22; 'cheers,': 0.22; 'am,': 0.23; 'cc:addr:gmail.com': 0.24; 'header :In-Reply-To:1': 0.24; "i've": 0.25; 'header:User-Agent:1': 0.26; 'figure': 0.27; 'order.': 0.27; 'correct': 0.28; 'function': 0.28; 'fine': 0.28; 'looks': 0.29; 'request,': 0.29; "i'm": 0.30; 'probably': 0.31; 'received:com.au': 0.33; "i'll": 0.33; 'worked': 0.34; 'so,': 0.35; 'mapping': 0.35; 'nov': 0.35; 'protocol': 0.35; 'skip:> 10': 0.35; 'subject:: ': 0.37; 'thanks': 0.37; 'charset :us-ascii': 0.37; 'shared': 0.38; 'subject:-': 0.39; 'rather': 0.39; 'easy': 0.60; 'your': 0.60; 'hope': 0.61; 'identify': 0.61; 'per': 0.62; 'between': 0.65; 'cameron': 0.66; 'effective.': 0.66; 'submission': 0.67; 'records': 0.70; 'handing': 0.84; 'responses': 0.93 Content-Disposition: inline In-Reply-To: <5A3A00A6-CFD2-42FC-9C87-6F8C6861F775@ravnalaska.net> User-Agent: Mutt/1.5.23 (2014-03-12) X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=cK4dyQqN c=1 sm=1 tr=0 a=EBcx3FSHdMIVXc4TnVAPjw==:117 a=EBcx3FSHdMIVXc4TnVAPjw==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=vrnE16BAAAAA:8 a=kj9zAlcOel0A:10 a=qtqOOiqGOCEA:10 a=-ZDudStxAAAA:8 a=pGLkceISAAAA:8 a=JpT--Tz6xp37daRgGcEA:9 a=BrQdLJnRfG6GoIWK:21 a=bvHrlFRSrOXIePz0:21 a=CjuIK1q_8ugA:10 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99284 On 23Nov2015 12:22, Israel Brewster wrote: >On Nov 23, 2015, at 11:51 AM, Ian Kelly wrote: >> Concurrency, ugh. I'm a big concurrency fan myself. >> It's probably better just to have a Condition/Event per thread and >> have the response thread identify the correct one to notify, rather >> than just notify a single shared Condition and hope the threads wake >> up in the right order. > >Tell me about it :-) I've actually never worked with conditions or >notifications (actually even this bi-drectional type of communication is new >to me), so I'll have to look into that and figure it out. Thanks for the >information! I include a tag with every request, and have the responses include the tag; the request submission function records the response hander in a mapping by tag and the response handing thread looks up the mapping and passes the response to the right handler. Works just fine and avoids all the worrying about ordering etc. Israel, do you have control over the protocol between you and your subprocess? If so, adding tags is easy and effective. Cheers, Cameron Simpson