Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99286
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Kaynor <ckaynor@zindagigames.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Bi-directional sub-process communication |
| Date | Mon, 23 Nov 2015 14:43:25 -0800 |
| Lines | 50 |
| Message-ID | <mailman.79.1448318633.2291.python-list@python.org> (permalink) |
| References | <5A3A00A6-CFD2-42FC-9C87-6F8C6861F775@ravnalaska.net> <20151123214516.GA56871@cskk.homeip.net> <F76E321F-3DE0-4FF7-90B4-5EA8A1017C71@ravnalaska.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de 8+LUOtSB3Pa3qvFUWVLClQ4HxM8KSCkTWsxL04ZCA5YA== |
| Return-Path | <ckaynor@zindagigames.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'receives': 0.03; 'memory.': 0.05; 'that?': 0.05; '"as': 0.07; 'option,': 0.07; 'subject:skip:c 10': 0.07; 'callback': 0.09; 'global,': 0.09; 'subject:process': 0.09; 'threads,': 0.09; 'thread': 0.10; '23,': 0.16; 'cheap.': 0.16; 'follow-up': 0.16; 'limit,': 0.16; 'processor,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:sub': 0.16; 'thread.': 0.16; 'threading': 0.16; 'threads': 0.16; 'wrote:': 0.16; 'memory': 0.17; 'implementing': 0.18; 'variable': 0.18; 'all,': 0.20; '2015': 0.20; 'second': 0.24; 'implemented': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'requests': 0.25; 'sort': 0.25; 'chris': 0.26; 'checking': 0.27; 'handling': 0.27; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'cpu': 0.29; 'dictionary': 0.29; 'once,': 0.29; 'thread,': 0.29; 'allows': 0.30; 'code': 0.30; 'checks': 0.30; 'probably': 0.31; 'option': 0.31; 'generally': 0.32; 'getting': 0.33; 'run': 0.33; 'useful': 0.33; 'running': 0.34; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'could': 0.35; 'i.e.': 0.35; 'nov': 0.35; 'step': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'cases': 0.36; 'depends': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'available.': 0.37; 'received:209.85.213': 0.37; 'doing': 0.38; 'itself': 0.38; 'received:209': 0.38; 'goes': 0.39; 'data': 0.39; 'does': 0.39; 'subject:-': 0.39; 'rather': 0.39; 'resources': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'some': 0.40; 'easy': 0.60; 'waiting': 0.60; 'avoid': 0.61; 'provide': 0.61; 'back': 0.62; 'per': 0.62; 'skip:n 10': 0.62; 'making': 0.62; 'more': 0.63; 'between': 0.65; 'benefit': 0.66; 'request.': 0.66; 'reply': 0.68; 'reply,': 0.72; 'dispatched': 0.84; 'replies.': 0.84; 'single,': 0.84; 'tie': 0.84; 'to:name:python': 0.84; 'viable': 0.84; 'wakes': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=zindagigames-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=SdjjjDloMugSnBB6Vz1u/KwiXRIS6WB1s5YunA0fs4g=; b=C1KkwETJazhS1/QxUxJXYh6dhgRjl6VX43OrocU9vnlU7qZBcqkz/tP15XHJIJiCh7 6LWHKQs+jDT/TP12Sw+JipQNo3kvvRRVH+VbqHkJ1zSJVaSkrRSaQ8eZp9zwxsTNpadF zCfaxTuwopwX2FEYlLt+F4JHr5jlGQOWkZZctmO3ty7ZErsErVDGZDVhS4Epq57AF95F 1nIDptYJS+nmagYR96Dle7D/I9nlq6OcBTzC5Zy27mq7dYIKjZsySdijrKYWXJDmEiUT wu3GocEZQuKZC0R7Sd2SxfIub/O1pGsoM65AZl+vC7BGv69wPDxEhoXtZyeN/jd+8Nlj CMFA== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=SdjjjDloMugSnBB6Vz1u/KwiXRIS6WB1s5YunA0fs4g=; b=Qnoser3ZaWXNdY4ltPbP4A4ZstGCfmE4ulKBmCS238PdIdFIAE4arudTQW18jO37el z3BHRlVenJ8NmeKeSynI+mvhRF+4i+Uiwmq/Rw/qZngRZydp7ZEMZjoh4mXpAmoZo0uM U/3aBNryle0z+646MbQTPavTO0gR7uoUzDgVkMvXkCJlEI7OA2vkjLMsUKtiheo25S87 8NwGMQzt4qCNMlkBZqaNF0Q6GRO0luZ9PwzXzO3dzr2hws4IdeI4Jbt73cv13a8YUNry wKy2XkV/Y3FIOM0z4CgOBNdj69hzWlo4KUr0tEpBl9Zbuu3sVJAhBcF7Ba5lm8sWZGPD 3Shw== |
| X-Gm-Message-State | ALoCoQnymk9o/WuNoMkE9LeM3hj+Z72xgP1b73hdIYznZjZ4caQ+kdTd1QkC/b8hx3kTSCdUH4Zz |
| X-Received | by 10.31.171.202 with SMTP id u193mr21650592vke.12.1448318624782; Mon, 23 Nov 2015 14:43:44 -0800 (PST) |
| In-Reply-To | <F76E321F-3DE0-4FF7-90B4-5EA8A1017C71@ravnalaska.net> |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.20+ |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:99286 |
Show key headers only | View raw
On Mon, Nov 23, 2015 at 2:18 PM, Israel Brewster <israel@ravnalaska.net> wrote: > 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? There are a few ways I could see handling this, without having the threads spinning and consuming CPU: 1. Don't worry about having the follow-up code run in the same thread, and use a simple callback. This callback could be dispatched to a thread via a work queue, however you may not get the same thread as the one that made the request. This is probably the most efficient method to use, as the threads can continue doing other work while waiting for a reply, rather than blocking. It does make it harder to maintain state between the pre- and post-request functions, however. 2. Have a single, global, event variable that wakes all threads waiting on a reply, each of which then checks to see if the reply is for it, or goes back to sleep. This is good if most of the time, only a few threads will be waiting for a reply, and checking if the correct reply came in is cheap. This is probably good enough, unless you have a LOT of threads (hundreds). 3. Have an event per thread. This will use less CPU than the second option, however does require more memory and OS resources, and so will not be viable for huge numbers of threads, though if you hit the limit, you are probably using threads wrong. 4. Have an event per request. This is only better than #3 if a single thread may make multiple requests at once, and can do useful work when any of them get a reply back (if they need all, it will make no difference). Generally, I would use option #1 or #2. Option 2 has the advantage of making it easy to write the functions that use the functionality, while option 1 will generally use fewer resources, and allows threads to continue to be used while waiting for replies. How much of a benefit that is depends on exactly what you are doing. Option #4 would probably be better implemented using option #1 in all cases to avoid problems with running out of OS memory - threading features generally require more limited OS resources than memory. Option #3 will also often run into the same issues as option #4 in the cases it will provide any benefit over option #2. Chris
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Bi-directional sub-process communication Chris Kaynor <ckaynor@zindagigames.com> - 2015-11-23 14:43 -0800
csiph-web