Cannot step through asynchronous iterator manually
Frank Millman
frank at chagford.com
Sat Jan 30 08:45:51 EST 2016
"Oscar Benjamin" wrote in message
news:CAHVvXxSA0Yq4VOYy6qycgXxVpL5zZGM8muUi+1VmeZD8CRgtvg at 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
More information about the Python-list
mailing list