Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Frank Millman" Newsgroups: comp.lang.python Subject: Re: Question about asyncio and blocking operations Date: Thu, 28 Jan 2016 11:13:53 +0200 Lines: 25 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de JtJRtU/xWE825Od6Fye6ogNkvGVH7p21GvKxBH6w0B0A== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'handler': 0.04; 'none,': 0.05; 'subject:Question': 0.05; 'bug.': 0.07; 'handler.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'assume': 0.11; 'jan': 0.11; 'exception': 0.13; 'wed,': 0.15; '2016': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'skip:n 70': 0.16; 'swallows': 0.16; 'think?': 0.16; 'thread.': 0.16; 'wrote:': 0.16; 'am,': 0.23; 'seems': 0.23; 'wrote': 0.23; 'header :In-Reply-To:1': 0.24; 'discussion': 0.24; 'url:bugs': 0.24; 'requests': 0.25; "doesn't": 0.26; 'header:X-Complaints-To:1': 0.26; 'separate': 0.27; 'that.': 0.30; 'work.': 0.30; 'run': 0.33; 'url:python': 0.33; 'url:org': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'test': 0.39; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'skip:u 10': 0.61; 'back': 0.62; 'between': 0.65; 'results': 0.66; 'frank': 0.72; 'present.': 0.72; 'fascinating': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 197.89.169.53 In-Reply-To: X-MSMail-Priority: Normal Importance: Normal X-Newsreader: Microsoft Windows Live Mail 15.4.3502.922 X-MimeOLE: Produced By Microsoft MimeOLE V15.4.3502.922 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:102176 "Ian Kelly" wrote in message news:CALwzidkr-fT6S6wH2caNaxyQvUdAw=x7XDqkqOfNRrwzwnjvOQ@mail.gmail.com... > > On Wed, Jan 27, 2016 at 10:14 AM, Ian Kelly wrote: > > Unfortunately this doesn't actually work at present. > > EventLoop.run_in_executor swallows the StopIteration exception and > > just returns None, which I assume is a bug. > > http://bugs.python.org/issue26221 > Thanks for that. Fascinating discussion between you and GvR. Reading it gave me an idea. Run the database handler in a separate thread. Use a queue.Queue to send requests to the handler. Use an asyncio.Queue to send results back to the caller, which can call 'await q.get()'. I ran a quick test and it seems to work. What do you think? Frank