Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102308 > unrolled thread
| Started by | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| First post | 2016-01-30 18:22 +0000 |
| Last post | 2016-01-30 18:22 +0000 |
| 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.
Re: Cannot step through asynchronous iterator manually Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-01-30 18:22 +0000
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Date | 2016-01-30 18:22 +0000 |
| Subject | Re: Cannot step through asynchronous iterator manually |
| Message-ID | <mailman.135.1454178169.2338.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web