[Python-ideas] awaiting iterables

Guido van Rossum guido at python.org
Sun May 3 02:27:51 CEST 2015


You can try to place these in a separate module, but in the end they still
depend on asyncio. You'll find out why when you try to implement any of
them. Don't dismiss the effort that went into asyncio too lightly.

On Sat, May 2, 2015 at 3:18 PM, Piotr Jurkiewicz <
piotr.jerzy.jurkiewicz at gmail.com> wrote:

> I know that. But the problem with wait() is that it returns Tasks, not
> their results directly. So user has to unpack them manually.
>
> Furthermore, after introduction of `await`, its name will become
> problematic. It will reassembles `await` too much and can cause a
> confusion. Its usage would result in an awkward 'await wait()'.
>
> There is a function gather(*coros_or_futures) which returns results list
> directly, like the function all_done() I proposed.
>
> But there is no function gather_any(*coros_or_futures), to return just a
> result of the first done coroutine. (One can achieve it with
> wait(return_when=FIRST_COMPLETED) but as mentioned before, it does not
> return a result directly, so there is no symmetry with gather())
>
> Function as_completed() returns indeed an iterator over the futures as
> they complete, but it is not compatible with the 'async for' protocol
> proposed in PEP 492. So new function has to be created anyway.
>
> Therefore I deliberately placed these functions in a new asynctools
> module, not in the asyncio module: to emphasize that they are supposed to
> be used with the new-style coroutines, proposed in PEP 492.
>
> I wanted to achieve simplicity (by returning results directly) and
> symmetry (all_done()/any_done()).
>
> Piotr
>
>
> On 2015-05-02 23:29, Guido van Rossum wrote:
>
>> The asyncio package already has this functionality; check out wait() (it
>> has various options), as_completed(), gather().
>>
>


-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150502/373be494/attachment.html>


More information about the Python-ideas mailing list