Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102121
| 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 | Tue, 26 Jan 2016 16:15:30 +0200 |
| Lines | 40 |
| Message-ID | <mailman.11.1453820010.2338.python-list@python.org> (permalink) |
| References | <n8038j$575$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; format=flowed; charset="iso-8859-1"; reply-type=response |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de bUdfZ615qXux0z9aABWZywgBj37Sqr4n9xt5YmyNjRjA== |
| 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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'ignored': 0.05; 'subject:Question': 0.05; 'caller': 0.07; 'front-end': 0.07; 'back-end': 0.09; 'cursor': 0.09; 'iterate': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'requested.': 0.09; 'rows': 0.09; 'tackle': 0.09; 'def': 0.13; 'operation.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'row': 0.16; 'stage.': 0.16; 'typical': 0.18; 'together.': 0.20; 'aspect': 0.22; 'bit': 0.23; 'seems': 0.23; 'wrote': 0.23; 'header :In-Reply-To:1': 0.24; 'header:X-Complaints-To:1': 0.26; 'yield': 0.27; 'developing': 0.28; 'another.': 0.29; 'blocking': 0.29; 'system,': 0.30; 'that.': 0.30; 'possibly': 0.32; 'run': 0.33; 'usually': 0.33; 'right?': 0.33; "isn't": 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'list.': 0.37; 'does': 0.39; 'application': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'future': 0.60; 'clients': 0.61; 'making': 0.62; 'worth': 0.67; 'frank': 0.72; 'sound': 0.72; 'mention.': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | 197.89.154.138 |
| In-Reply-To | <n8038j$575$1@ger.gmane.org> |
| 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:102121 |
Show key headers only | View raw
"Frank Millman" wrote in message news:n8038j$575$1@ger.gmane.org...
>
> I am developing a typical accounting/business application which involves a
> front-end allowing clients to access the system, a back-end connecting to
> a database, and a middle layer that glues it all together.
>
[...]
>
> There was one aspect that I deliberately ignored at that stage. I did not
> change the database access to an asyncio approach, so all reading
> from/writing to the database involved a blocking operation. I am now ready
> to tackle that.
I am making some progress, but I have found a snag - possibly unavoidable,
but worth a mention.
Usually when I retrieve rows from a database I iterate over the cursor -
def get_rows(sql, params):
cur.execute(sql, params)
for row in cur:
yield row
If I create a Future to run get_rows(), I have to 'return' the result so
that the caller can access it by calling future.result().
If I return the cursor, I can iterate over it, but isn't this a blocking
operation? As far as I know, the DB adaptor will only actually retrieve the
row when requested.
If I am right, I should call fetchall() while inside get_rows(), and return
all the rows as a list.
This seems to be swapping one bit of asynchronicity for another.
Does this sound right?
Frank
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Question about asyncio and blocking operations "Frank Millman" <frank@chagford.com> - 2016-01-26 16:15 +0200
csiph-web