[Python-Dev] ABCs - Re: PEP 492: async/await in Python; version 4
Jim J. Jewett
jimjjewett at gmail.com
Mon May 4 19:35:57 CEST 2015
On Sun May 3 08:32:02 CEST 2015, Stefan Behnel wrote:
> Ok, fair enough. So, how would you use this new protocol manually then?
> Say, I already know that I won't need to await the next item that the
> iterator will return. For normal iterators, I could just call next() on it
> and continue the for-loop. How would I do it for AIterators?
Call next, then stick it somewhere it be waited on.
Or is that syntactically illegal, because of the separation between
sync and async?
The "asych for" seems to assume that you want to do the waiting right
now, at each step. (At least as far as this thread of the logic goes;
something else might be happening in parallel via other threads of
> BTW, I guess that this "AIterator", or rather "AsyncIterator", needs to be
> a separate protocol (and ABC) then. Implementing "__aiter__()" and
> "__anext__()" seems perfectly reasonable without implementing (or using) a
> That means we also need an "AsyncIterable" as a base class for it.
> That might even help us to decide if we need new builtins (or helpers)
> aiter() and anext() in order to deal with these protocols.
I hope not; they seem more like specialized versions of functions,
such as are found in math or cmath. Ideally, as much as possible of
this PEP should live in asycio, rather than appearing globally.
Which reminds me ... *should* the "await" keyword work with any future,
or is it really intentionally restricted to use with a single library
module and 3rd party replacements?
If there are still threading problems with my replies, please
email me with details, so that I can try to resolve them. -jJ
More information about the Python-Dev