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


Groups > comp.lang.python > #102198

Re: Question about asyncio and blocking operations

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Question about asyncio and blocking operations
Date Thu, 28 Jan 2016 14:49:25 -0700
Lines 28
Message-ID <mailman.66.1454017808.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> <n8ct18$fu4$1@ger.gmane.org> <CALwzidnGbz7kM=D7MKua2tA9-csFn9u0OHL0w-X5Bbixpcw4Ow@mail.gmail.com> <n8dgas$s1u$1@ger.gmane.org> <CALwzidn6NfT_O0cfHw1itWja81+MW3scHuEcADVCen3ix6z73w@mail.gmail.com> <CAGqiJR-kbF2HDTPRG=49yEDkyZZRQbUC-=3Dq_bApab2exsKAw@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de YtLcgrFJuUKGTFxaXgTbfQDZ3uARTERDEusT7YLRZYGw==
Return-Path <ian.g.kelly@gmail.com>
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; 'subject:Question': 0.05; 'caller': 0.07; 'concurrently': 0.07; 'executed': 0.07; 'wrapper': 0.07; 'appropriate.': 0.09; 'buffer,': 0.09; 'cursor': 0.09; 'empty,': 0.09; 'loop.': 0.09; 'underlying': 0.09; 'jan': 0.11; 'thu,': 0.15; '2016': 0.16; 'deque': 0.16; 'producer': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'suggestion.': 0.16; 'threads': 0.16; 'wrote:': 0.16; 'am,': 0.23; 'seems': 0.23; 'header:In-Reply-To:1': 0.24; 'requests': 0.25; 'message- id:@mail.gmail.com': 0.27; 'this.': 0.28; 'interface': 0.29; 'queue': 0.29; 'true.': 0.33; 'received:google.com': 0.35; 'could': 0.35; "isn't": 0.35; 'received:209.85': 0.36; 'to:addr :python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'data': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'your': 0.60; 'entire': 0.61; 'different': 0.63; 'frank': 0.72; 'actually,': 0.84; 'to:name:python': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=8eYYGuoZ9ByOUkmNfxvzinE7LTIG3OjmvmphM4e8wxg=; b=wR1o2l6Yts4pmVU4vRcg3AAzR4PR3NmzJXAoxzbGxSqz3d+b9rKDul7EPWGeZo6a17 kK4gg3BSQ6n0ixK6lqnm/ALiDkWI+ju8uPbjZ55pIgmb39svmmmiNfuSJgbyWlc6CAXy J5ofBPhajmA4uMwM8Z//eZfz5LarSCuGM9HSXGD/6rxlBAsUZUjXflftH+0RfxXCFT0f Fz8YWWzp24uBvGl01CrZgaddPiyKqO/ojHvkVKs54jVooF5m2anQ5YtcTly3Oz4BoMrF ZQxYjzVWIfil5Gr8ptBoQu6IekQXDAyjMwFjYy2FiSuxehyZGxhSLSQH5+lwlPlhfY9k WJNQ==
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=8eYYGuoZ9ByOUkmNfxvzinE7LTIG3OjmvmphM4e8wxg=; b=fIjbqk54OekVmOOIM+IUd0+iICdowNLVyAFhjDzjBvmyn73lfq0rjV+E06sv2lAk29 aJmjy7ocH0903DWPr4mHWKmAfeoX/C1RW4aggHn9zHUC+jnwcxWntTtRgAH4xMlB1Mum SHSCnXsiVSrUUeYuHQlt5Dfva6eyg4uky3XGQLsk+xENmiICrMy+buIJrIcLSIeK+Gh+ FLg8RRtm1q4z95vat3WuXkEGUsi484DzZ3kInBAEBoXqXoRuw8KggxBLIcd1WuW6DZj5 j1kLUrA8TdfezBis5lCUDHfGd7NecWCvmwFfxUdeAVSHSiSO3hJSJT3uSsEE5U6YlT6F Irew==
X-Gm-Message-State AG10YOS/mDcch2psTwK5jvREUJrngM14x7D0RqoiG4c7UB3FWuD6lQwOlt/cTwJAbSLUhi/qgiCb0eWURwTTJw==
X-Received by 10.50.102.40 with SMTP id fl8mr6058927igb.85.1454017805253; Thu, 28 Jan 2016 13:50:05 -0800 (PST)
In-Reply-To <CAGqiJR-kbF2HDTPRG=49yEDkyZZRQbUC-=3Dq_bApab2exsKAw@mail.gmail.com>
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:102198

Show key headers only | View raw


On Thu, Jan 28, 2016 at 2:23 PM, Maxime S <maxischmeii@gmail.com> wrote:
>
> 2016-01-28 17:53 GMT+01:00 Ian Kelly <ian.g.kelly@gmail.com>:
>>
>> On Thu, Jan 28, 2016 at 9:40 AM, Frank Millman <frank@chagford.com> wrote:
>>
>> > The caller requests some data from the database like this.
>> >
>> >    return_queue = asyncio.Queue()
>> >    sql = 'SELECT ...'
>> >    request_queue.put((return_queue, sql))
>>
>> Note that since this is a queue.Queue, the put call has the potential
>> to block your entire event loop.
>>
>
> Actually, I don't think you actually need an asyncio.Queue.
>
> You could use a simple deque as a buffer, and call fetchmany() when it is
> empty, like that (untested):

True. The asyncio Queue is really just a wrapper around a deque with
an interface designed for use with the producer-consumer pattern. If
the producer isn't a coroutine then it may not be appropriate.

This seems like a nice suggestion. Caution is advised if multiple
cursor methods are executed concurrently since they would be in
different threads and the underlying cursor may not be thread-safe.

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


Thread

Re: Question about asyncio and blocking operations Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-28 14:49 -0700

csiph-web