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


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

Re: Cannot step through asynchronous iterator manually

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2016-01-30 09:42 -0700
Last post2016-01-30 09:42 -0700
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 Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-30 09:42 -0700

#102306 — Re: Cannot step through asynchronous iterator manually

FromIan Kelly <ian.g.kelly@gmail.com>
Date2016-01-30 09:42 -0700
SubjectRe: Cannot step through asynchronous iterator manually
Message-ID<mailman.132.1454172216.2338.python-list@python.org>
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.

[toc] | [standalone]


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


csiph-web