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


Groups > comp.lang.python > #102308

Re: Cannot step through asynchronous iterator manually

From Oscar Benjamin <oscar.j.benjamin@gmail.com>
Newsgroups comp.lang.python
Subject Re: Cannot step through asynchronous iterator manually
Date 2016-01-30 18:22 +0000
Message-ID <mailman.135.1454178169.2338.python-list@python.org> (permalink)
References (2 earlier) <n8hrs1$orn$1@ger.gmane.org> <CAHVvXxSA0Yq4VOYy6qycgXxVpL5zZGM8muUi+1VmeZD8CRgtvg@mail.gmail.com> <n8ieqk$a05$1@ger.gmane.org> <CAHVvXxST-inCFVnTGhUXpAAUc_xKfrwHKbqzSJka1O4rqB2YHA@mail.gmail.com> <CALwzid=ukw6izyRSdaXYsUNacc-gYD1K-x=_1r2MJu9DF9Xa1g@mail.gmail.com>

Show all headers | View raw


On 30 January 2016 at 16:42, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>> AFAICT there's no generator-function-style syntax for writing an async
>> iterator so you'd have to make a class with the appropriate methods if
>> you wanted to be able to loop over aslice with async for.
>
> Before you go any further with this, be sure to check out the aitertools
> third-party module. I haven't done anything with it myself, but it already
> claims to provide aiter and anext as well as async versions of everything
> in the standard itertools module.

Right you are. There is aslice and it is implemented as a class with
__anext__ etc. methods:
https://github.com/asyncdef/aitertools/blob/master/aitertools/__init__.py#L747

My original suggestion just becomes:

from aitertools import alist, islice

rows = await alist(islice(cur, 2))  # pull at most 2 rows

--
Oscar

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


Thread

Re: Cannot step through asynchronous iterator manually Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-01-30 18:22 +0000

csiph-web