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


Groups > comp.lang.python > #102304 > unrolled thread

Re: Cannot step through asynchronous iterator manually

Started by"Frank Millman" <frank@chagford.com>
First post2016-01-30 15:45 +0200
Last post2016-01-30 15:45 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#102304 — Re: Cannot step through asynchronous iterator manually

From"Frank Millman" <frank@chagford.com>
Date2016-01-30 15:45 +0200
SubjectRe: Cannot step through asynchronous iterator manually
Message-ID<mailman.130.1454161573.2338.python-list@python.org>
"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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web