mirror of
https://github.com/python/cpython.git
synced 2025-12-10 11:00:14 +00:00
GH-78530: add support for generators in asyncio.wait (#102761)
This commit is contained in:
parent
f33b33eb31
commit
4f5774f648
4 changed files with 24 additions and 0 deletions
|
|
@ -804,6 +804,10 @@ Waiting Primitives
|
||||||
.. versionchanged:: 3.11
|
.. versionchanged:: 3.11
|
||||||
Passing coroutine objects to ``wait()`` directly is forbidden.
|
Passing coroutine objects to ``wait()`` directly is forbidden.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.12
|
||||||
|
Added support for generators yielding tasks.
|
||||||
|
|
||||||
|
|
||||||
.. function:: as_completed(aws, *, timeout=None)
|
.. function:: as_completed(aws, *, timeout=None)
|
||||||
|
|
||||||
Run :ref:`awaitable objects <asyncio-awaitables>` in the *aws*
|
Run :ref:`awaitable objects <asyncio-awaitables>` in the *aws*
|
||||||
|
|
|
||||||
|
|
@ -241,6 +241,9 @@ asyncio
|
||||||
:mod:`asyncio` does not support legacy generator-based coroutines.
|
:mod:`asyncio` does not support legacy generator-based coroutines.
|
||||||
(Contributed by Kumar Aditya in :gh:`102748`.)
|
(Contributed by Kumar Aditya in :gh:`102748`.)
|
||||||
|
|
||||||
|
* :func:`asyncio.wait` now accepts generators yielding tasks.
|
||||||
|
(Contributed by Kumar Aditya in :gh:`78530`.)
|
||||||
|
|
||||||
inspect
|
inspect
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1373,6 +1373,22 @@ class BaseTaskTests:
|
||||||
self.assertEqual(res, 42)
|
self.assertEqual(res, 42)
|
||||||
self.assertAlmostEqual(0.15, loop.time())
|
self.assertAlmostEqual(0.15, loop.time())
|
||||||
|
|
||||||
|
|
||||||
|
def test_wait_generator(self):
|
||||||
|
async def func(a):
|
||||||
|
return a
|
||||||
|
|
||||||
|
loop = self.new_test_loop()
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
tasks = (self.new_task(loop, func(i)) for i in range(10))
|
||||||
|
done, pending = await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED)
|
||||||
|
self.assertEqual(len(done), 10)
|
||||||
|
self.assertEqual(len(pending), 0)
|
||||||
|
|
||||||
|
loop.run_until_complete(main())
|
||||||
|
|
||||||
|
|
||||||
def test_as_completed(self):
|
def test_as_completed(self):
|
||||||
|
|
||||||
def gen():
|
def gen():
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
:func:`asyncio.wait` now accepts generators yielding tasks. Patch by Kumar Aditya.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue