Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Wed, Nov 30, 2016 at 8:34 PM, Ian Kelly wrote: > To be pedantic, it should be more like: > > return type(aiter).__dict__['__anext__']() And of course, if you don't find it there then to be proper you also have to walk the MRO and check all of those class dicts as well. -- https://mail.pyt

Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Wed, Nov 30, 2016 at 5:05 PM, Steve D'Aprano wrote: > On Wed, 30 Nov 2016 07:51 pm, Ian Kelly wrote: > >> On Wed, Nov 30, 2016 at 1:29 AM, Frank Millman wrote: > >>> But I found it easy to write my own - >>> >>> async def anext(aiter): >>>return await aiter.__anext__() >> >> Even simpler:

Re: async enumeration - possible?

2016-11-30 Thread Steve D'Aprano
On Wed, 30 Nov 2016 07:51 pm, Ian Kelly wrote: > On Wed, Nov 30, 2016 at 1:29 AM, Frank Millman wrote: >> But I found it easy to write my own - >> >> async def anext(aiter): >>return await aiter.__anext__() > > Even simpler: > > def anext(aiter): > return aiter.__anext__() With very

Re: async enumeration - possible?

2016-11-30 Thread Marko Rauhamaa
Ian Kelly : > On Wed, Nov 30, 2016 at 2:28 AM, Marko Rauhamaa wrote: >> Each "await" in a program is a (quasi-)blocking state. In each state, >> the program needs to be ready to process different input events. > > Well, that's why you can have multiple different coroutines awaiting > at any given

Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Wed, Nov 30, 2016 at 2:28 AM, Marko Rauhamaa wrote: > "Frank Millman" : > >> "Marko Rauhamaa" wrote in message news:87d1hd4d5k@elektro.pacujo.net... >>> I don't think bulk iteration in asynchronous programming is ever that >>> great of an idea. You want to be prepared for more than one

Re: async enumeration - possible?

2016-11-30 Thread Marko Rauhamaa
"Frank Millman" : > "Marko Rauhamaa" wrote in message news:87d1hd4d5k@elektro.pacujo.net... >> I don't think bulk iteration in asynchronous programming is ever that >> great of an idea. You want to be prepared for more than one possible >> stimulus in any given state. IOW, a state machi

Re: async enumeration - possible?

2016-11-30 Thread Peter Otten
Steve D'Aprano wrote: > On Wed, 30 Nov 2016 07:07 am, Marko Rauhamaa wrote: > >> Terry Reedy : >> >>> On 11/29/2016 9:25 AM, Frank Millman wrote: >>> Is there any technical reason for this, or is it just that no-one has got around to writing an asynchronous version yet? >>> >>> Google'

Re: async enumeration - possible?

2016-11-30 Thread Frank Millman
"Ian Kelly" wrote in message news:CALwzid=hrijtv4p1_6frkqub25-o1i8ouquxozd+aujgl7+...@mail.gmail.com... On Wed, Nov 30, 2016 at 1:29 AM, Frank Millman wrote: > > async def anext(aiter): >return await aiter.__anext__() Even simpler: def anext(aiter): return aiter.__anext__() As a gen

Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Wed, Nov 30, 2016 at 1:29 AM, Frank Millman wrote: > "Marko Rauhamaa" wrote in message news:87d1hd4d5k@elektro.pacujo.net... >> >> >> One of the more useful ones might be: >> >> o = await anext(ait) >> > > Definitely! > > But I found it easy to write my own - > > async def anext(aiter)

Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Wed, Nov 30, 2016 at 1:20 AM, Chris Angelico wrote: > Hmm. The thing is, comprehensions and generators are implemented with > their own nested functions. So I would expect that their use of async > is independent of the function they're in. But maybe we have a bug > here? > async def spam(

Re: async enumeration - possible?

2016-11-30 Thread Frank Millman
"Marko Rauhamaa" wrote in message news:87d1hd4d5k@elektro.pacujo.net... One of the more useful ones might be: o = await anext(ait) Definitely! But I found it easy to write my own - async def anext(aiter): return await aiter.__anext__() [...] I don't think bulk iteration in

Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Wed, Nov 30, 2016 at 12:53 AM, Marko Rauhamaa wrote: > I have a couple of points to make with my question: > > * We are seeing the reduplication of a large subset of Python's >facilities. I really wonder if the coroutine fad is worth the price. I don't think there's any technical reason w

Re: async enumeration - possible?

2016-11-30 Thread Chris Angelico
On Wed, Nov 30, 2016 at 7:10 PM, Ian Kelly wrote: > On Tue, Nov 29, 2016 at 8:22 PM, Chris Angelico wrote: >> Interestingly, I can't do that in a list comp: >> > [x async for x in aiterable] >> File "", line 1 >> [x async for x in aiterable] >>^ >> SyntaxError: invalid synta

Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Tue, Nov 29, 2016 at 8:22 PM, Chris Angelico wrote: > Interestingly, I can't do that in a list comp: > [x async for x in aiterable] > File "", line 1 > [x async for x in aiterable] >^ > SyntaxError: invalid syntax > > Not sure why. Because you tried to use an async compr

Re: async enumeration - possible?

2016-11-29 Thread Marko Rauhamaa
Chris Angelico : > On Wed, Nov 30, 2016 at 7:07 AM, Marko Rauhamaa wrote: > Any of these that depend on pumping the entire iterable can simply > synchronify [1] the iterable: One of the more useful ones might be: o = await anext(ait) > list(x async for x in aiterable) > > Interestingly, I

Re: async enumeration - possible?

2016-11-29 Thread Frank Millman
"Frank Millman" wrote in message news:o1k355$da5$1...@blaine.gmane.org... Hi all Python 3.6 has introduced Asynchronous Generators, which work very well. [...] However, it does not allow you to enumerate over the generator output - [...] Is there any technical reason for this, or is it

Re: async enumeration - possible?

2016-11-29 Thread Chris Angelico
On Wed, Nov 30, 2016 at 7:07 AM, Marko Rauhamaa wrote: > Ok, so how about: > >aall(aiterable) >aany(aiterable) >class abytearray(aiterable[, encoding[, errors]]) >class adict(aiterable, **kwarg) >class afilter(coro, aiterable) >class afrozenset(aiterable) >aiter(object[

Re: async enumeration - possible?

2016-11-29 Thread Steve D'Aprano
On Wed, 30 Nov 2016 07:07 am, Marko Rauhamaa wrote: > Terry Reedy : > >> On 11/29/2016 9:25 AM, Frank Millman wrote: >> >>> Is there any technical reason for this, or is it just that no-one has >>> got around to writing an asynchronous version yet? >> >> Google's first hit for 'aenumerate' is >>

Re: async enumeration - possible?

2016-11-29 Thread Marko Rauhamaa
Terry Reedy : > On 11/29/2016 9:25 AM, Frank Millman wrote: > >> Is there any technical reason for this, or is it just that no-one has >> got around to writing an asynchronous version yet? > > Google's first hit for 'aenumerate' is > https://pythonwise.blogspot.com/2015/11/aenumerate-enumerate-for

Re: async enumeration - possible?

2016-11-29 Thread Terry Reedy
On 11/29/2016 9:25 AM, Frank Millman wrote: Is there any technical reason for this, or is it just that no-one has got around to writing an asynchronous version yet? Google's first hit for 'aenumerate' is https://pythonwise.blogspot.com/2015/11/aenumerate-enumerate-for-async-for.html Note that

Re: async enumeration - possible?

2016-11-29 Thread Ian Kelly
On Tue, Nov 29, 2016 at 7:25 AM, Frank Millman wrote: > However, it does not allow you to enumerate over the generator output - > async def main(): > > ... c = counter(5) > ... async for j, k in enumerate(c): > ... print(j, k) > ... print('done') > ... loop.run_until_compl

async enumeration - possible?

2016-11-29 Thread Frank Millman
Hi all Python 3.6 has introduced Asynchronous Generators, which work very well. Python 3.6.0b4 (default, Nov 22 2016, 05:30:12) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. import asyncio loop = asyncio.get_event_loop() async def