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


Groups > comp.lang.python > #102306

Re: Cannot step through asynchronous iterator manually

From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Cannot step through asynchronous iterator manually
Date 2016-01-30 09:42 -0700
Message-ID <mailman.132.1454172216.2338.python-list@python.org> (permalink)
References (1 earlier) <CALwzid=sSDSm8hdAN+ORJ54A_jEu9Wc8103iqGKAah8mrj-TXw@mail.gmail.com> <n8hrs1$orn$1@ger.gmane.org> <CAHVvXxSA0Yq4VOYy6qycgXxVpL5zZGM8muUi+1VmeZD8CRgtvg@mail.gmail.com> <n8ieqk$a05$1@ger.gmane.org> <CAHVvXxST-inCFVnTGhUXpAAUc_xKfrwHKbqzSJka1O4rqB2YHA@mail.gmail.com>

Show all headers | View raw


On Jan 30, 2016 7:13 AM, "Oscar Benjamin" <oscar.j.benjamin@gmail.com>
wrote:
>
> I haven't used PEP 492 yet but what about:
>
> async def aslice(asynciterator, end):
>     if end == 0:
>         return []
>    items = []
>    async for item in asynciterator:
>        items.append(item)
>        if len(items) == end:
>            break
>     return items
>
> rows = await aslice(cur, 2)
>
> 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.

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


Thread

Re: Cannot step through asynchronous iterator manually Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-30 09:42 -0700

csiph-web