Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102178

Re: Question about asyncio and blocking operations

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From "Frank Millman" <frank@chagford.com>
Newsgroups comp.lang.python
Subject Re: Question about asyncio and blocking operations
Date Thu, 28 Jan 2016 13:11:32 +0200
Lines 35
Message-ID <mailman.47.1453979513.2338.python-list@python.org> (permalink)
References <n8038j$575$1@ger.gmane.org> <n8818q$35e$1@ger.gmane.org> <CALwzidk-RBkB-vi6CgcEeoFHQrsoTFvqX9MqzDD=rnY5bOCRUg@mail.gmail.com> <n8aln3$fah$1@ger.gmane.org> <CALwzidn6TvN9W-2qnn2JYvJu8NHzn499nPtfjn9OHjdDcebVbA@mail.gmail.com> <CALwzidmmUeL3Sq9o6ZgKYM3-V22HCshG03wQqsXvhh6xy1otgQ@mail.gmail.com> <CALwzidkr-fT6S6wH2caNaxyQvUdAw=x7XDqkqOfNRrwzwnjvOQ@mail.gmail.com> <n8cm4k$ojk$1@ger.gmane.org> <CAPTjJmr162+K4LZeFpXruR6wxrHxbR-_wkrCLLDyR7kST+kjYg@mail.gmail.com>
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 WzKpWCD4uZ0IrtGYYlUG7gIwFPPHoUYWlnDv+r7fqCVQ==
Return-Path <python-python-list@m.gmane.org>
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; 'handler': 0.04; 'subject:Question': 0.05; 'caller': 0.07; 'covered.': 0.09; 'handler.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.11; 'thu,': 0.15; '2016': 0.16; 'async': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'sequencing': 0.16; 'skip:n 70': 0.16; 'think?': 0.16; 'thread.': 0.16; 'wrote:': 0.16; 'creates': 0.18; 'seems': 0.23; 'wrote': 0.23; 'header:In-Reply-To:1': 0.24; 'requests': 0.25; 'header:X -Complaints-To:1': 0.26; 'figure': 0.27; 'separate': 0.27; 'back.': 0.27; '(maybe': 0.29; 'queue': 0.29; 'request,': 0.29; 'that.': 0.30; 'work.': 0.30; "i'd": 0.31; 'run': 0.33; 'problem': 0.33; 'this?': 0.34; 'gets': 0.35; 'could': 0.35; 'instance': 0.35; 'tasks': 0.35; 'something': 0.35; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'one,': 0.37; 'wrong': 0.38; 'test': 0.39; 'to:addr:python.org': 0.40; 'back': 0.62; 'request.': 0.66; 'results': 0.66; 'risk': 0.68; 'feeling': 0.72; 'frank': 0.72; '"it': 0.84; 'gut': 0.84
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host 197.89.169.53
In-Reply-To <CAPTjJmr162+K4LZeFpXruR6wxrHxbR-_wkrCLLDyR7kST+kjYg@mail.gmail.com>
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 <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:102178

Show key headers only | View raw


"Chris Angelico"  wrote in message 
news:CAPTjJmr162+K4LZeFpXruR6wxrHxbR-_wkrCLLDyR7kST+kjYg@mail.gmail.com...
>
> On Thu, Jan 28, 2016 at 8:13 PM, Frank Millman <frank@chagford.com> wrote:
> > 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?
>
> My gut feeling is that any queue can block at either get or put ....
>

H'mm, I will have to think about that one, and figure out how to create a 
worst-case scenario. I will report back on that.

>
> The other risk is that the wrong result will be queried (two async
> tasks put something onto the queue - which one gets the first
> result?), which could either be coped with by simple sequencing (maybe
> this happens automatically, although I'd prefer a
> mathematically-provable result to "it seems to work"), or by wrapping
> the whole thing up in a function/class.
>

I *think* I have this one covered. When the caller makes a request, it 
creates an instance of an asyncio.Queue, and includes it with the request. 
The db handler uses this queue to send the result back.

Do you see any problem with this?

Frank

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Question about asyncio and blocking operations "Frank Millman" <frank@chagford.com> - 2016-01-28 13:11 +0200

csiph-web