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


Groups > comp.lang.python > #102304

Re: Cannot step through asynchronous iterator manually

Path csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail
From "Frank Millman" <frank@chagford.com>
Newsgroups comp.lang.python
Subject Re: Cannot step through asynchronous iterator manually
Date Sat, 30 Jan 2016 15:45:51 +0200
Lines 30
Message-ID <mailman.130.1454161573.2338.python-list@python.org> (permalink)
References <n8hjmt$b8n$1@ger.gmane.org> <CALwzid=sSDSm8hdAN+ORJ54A_jEu9Wc8103iqGKAah8mrj-TXw@mail.gmail.com> <n8hrs1$orn$1@ger.gmane.org> <CAHVvXxSA0Yq4VOYy6qycgXxVpL5zZGM8muUi+1VmeZD8CRgtvg@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 7a5IX/ksjVi3YGrtWe3ewwynH4giwp63Em1TjPgDuGkw==
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.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'elif': 0.04; 'base.': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rows': 0.09; 'thread': 0.10; '2))': 0.16; 'consume': 0.16; 'itertools': 0.16; 'readable': 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; 'skip:n 70': 0.16; 'variations': 0.16; 'wrote': 0.23; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'header:X -Complaints-To:1': 0.26; 'equivalent,': 0.29; 'idea,': 0.29; 'similar': 0.33; 'except': 0.34; 'but': 0.36; 'too': 0.36; 'should': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'your': 0.60; 'back': 0.62; 'more': 0.63; 'realise': 0.66; 'frank': 0.72; 'square': 0.76; 'leisure': 0.84; 'choose.': 0.91
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host 197.86.205.12
In-Reply-To <CAHVvXxSA0Yq4VOYy6qycgXxVpL5zZGM8muUi+1VmeZD8CRgtvg@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:102304

Show key headers only | View raw


"Oscar Benjamin"  wrote in message 
news:CAHVvXxSA0Yq4VOYy6qycgXxVpL5zZGM8muUi+1VmeZD8CRgtvg@mail.gmail.com...
>
> The simplest thing would just be to call list(cur) but I realise that
you don't want to consume more than 2 rows from the database so just
use islice:
>
> rows = list(islice(cur, 2))  # pull at most 2 rows
> if not rows:
>     # no rows
> elif len(rows) > 1:
>     # too many rows
> row = rows[0]
>

I like the idea, but I don't think it would work with an asychronous 
iterable. OTOH it should not be difficult to roll your own using the example 
in the itertools docs as a base. Except that the example uses next(it) 
internally, and this thread started with the fact that there is no 
asychronous equivalent, so I might be back to square one.

But these are all variations on a similar theme, so I don't think it matters 
which one I choose. I will go through them at my leisure and pick the most 
readable one.

Thanks

Frank

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


Thread

Re: Cannot step through asynchronous iterator manually "Frank Millman" <frank@chagford.com> - 2016-01-30 15:45 +0200

csiph-web