Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Israel Brewster Newsgroups: comp.lang.python Subject: Re: Bi-directional sub-process communication Date: Mon, 23 Nov 2015 13:18:58 -0900 Lines: 58 Message-ID: References: <5A3A00A6-CFD2-42FC-9C87-6F8C6861F775@ravnalaska.net> <20151123214516.GA56871@cskk.homeip.net> Mime-Version: 1.0 (Mac OS X Mail 9.1 \(3096.5\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de q6F+Vt/AiKzK+z5NUm2B4wmlx0mGkHskmwl19ieHe0CQ== 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; 'receives': 0.03; 'that?': 0.05; '"as': 0.07; 'puts': 0.07; 'subject:skip:c 10': 0.07; 'cc:addr:python-list': 0.09; '(actually': 0.09; 'encodes': 0.09; 'handler.': 0.09; 'keyed': 0.09; 'subject:process': 0.09; 'threads,': 0.09; 'thread': 0.10; ':-)': 0.12; 'do,': 0.15; '23,': 0.16; 'cc:name:python': 0.16; 'concurrency': 0.16; 'concurrency,': 0.16; 'processor,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'simpson': 0.16; 'subject:sub': 0.16; 'threads': 0.16; 'wake': 0.16; 'wrote:': 0.16; 'implementing': 0.18; 'passes': 0.18; '>>>': 0.20; 'cc:addr:python.org': 0.20; 'cc:2**1': 0.22; 'sends': 0.22; 'cheers,': 0.22; 'am,': 0.23; 'cc:addr:gmail.com': 0.24; 'header:In-Reply-To:1': 0.24; 'requests': 0.25; 'sort': 0.25; "i've": 0.25; 'appear': 0.26; 'sense': 0.26; 'figure': 0.27; 'order.': 0.27; 'separate': 0.27; 'data,': 0.27; 'correct': 0.28; 'function': 0.28; 'fine': 0.28; 'looks': 0.29; 'dictionary': 0.29; 'request,': 0.29; "i'm": 0.30; 'putting': 0.30; 'probably': 0.31; 'getting': 0.33; "i'll": 0.33; 'worked': 0.34; 'so,': 0.35; 'could': 0.35; 'i.e.': 0.35; 'mapping': 0.35; 'nov': 0.35; 'protocol': 0.35; 'step': 0.36; 'there': 0.36; 'basic': 0.36; 'child': 0.36; 'data.': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'thanks': 0.37; 'available.': 0.37; 'charset :us-ascii': 0.37; 'itself': 0.38; 'shared': 0.38; 'data': 0.39; 'subject:-': 0.39; 'rather': 0.39; 'still': 0.40; 'some': 0.40; 'easy': 0.60; 'waiting': 0.60; 'your': 0.60; 'hope': 0.61; 'header :Message-Id:1': 0.61; 'identify': 0.61; 'side': 0.62; 'back': 0.62; 'per': 0.62; 'skip:n 10': 0.62; 'between': 0.65; 'cameron': 0.66; 'difficulty': 0.66; 'effective.': 0.66; 'received:10.9': 0.66; 'submission': 0.67; 'records': 0.70; 'received:12': 0.81; 'handing': 0.84; 'single,': 0.84; 'tie': 0.84; 'responses': 0.93 X-Warning: RFC compliance checks disabled due to whitelist X-Warning: Reverse-Path DNS check skipped due to whitelist X-Warning: Maximum message size check skipped due to whitelist X-Warning: Realtime Block Lists skipped due to whitelist X-Warning: System filters skipped due to whitelist X-Warning: Domain filters skipped due to whitelist X-Warning: User filters skipped due to whitelist X-Warning: Anti-Spam check skipped due to whitelist X-Whitelist: 2147483645 X-Envelope-From: israel@ravnalaska.net X-Envelope-To: ian.g.kelly@gmail.com In-Reply-To: <20151123214516.GA56871@cskk.homeip.net> X-Mailer: Apple Mail (2.3096.5) 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:99285 On Nov 23, 2015, at 12:45 PM, Cameron Simpson wrote: >=20 > On 23Nov2015 12:22, Israel Brewster wrote: >> On Nov 23, 2015, at 11:51 AM, Ian Kelly = wrote: >>> Concurrency, ugh. >=20 > I'm a big concurrency fan myself. >=20 >>> 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. >>=20 >> 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! >=20 > 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. >=20 > Works just fine and avoids all the worrying about ordering etc. >=20 > Israel, do you have control over the protocol between you and your = subprocess? If so, adding tags is easy and effective. I do, and the basic concept makes sense. The one difficulty I am seeing = is getting back to the thread that requested the data. Let me know if = this makes sense or I am thinking about it wrong: - When a thread requests some data, it sends the request as a dictionary = containing a tag (unique to the thread) as well as the request - When the child processes the request, it encodes the response as a = dictionary containing the tag and the response data - A single, separate thread on the "master" side parses out responses as = they come in and puts them into a dictionary keyed by tag - The requesting threads, after putting the request into the Queue, = would then block waiting for data to appear under their key in the = dictionary Of course, that last step could be interesting - implementing the block = in such a way as to not tie up the processor, while still getting the = data "as soon" as it is available. Unless there is some sort of built-in = notification system I could use for that? I.e. the thread would = "subscribe" to a notification based on its tag, and then wait for = notification. When the master processing thread receives data with said = tag, it adds it to the dictionary and "publishes" a notification to that = tag. Or perhaps the notification itself could contain the payload?=20 Thanks for the information! >=20 > Cheers, > Cameron Simpson