Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4f5774f

Browse filesBrowse files
GH-78530: add support for generators in asyncio.wait (#102761)
1 parent f33b33e commit 4f5774f
Copy full SHA for 4f5774f

File tree

Expand file treeCollapse file tree

4 files changed

+24
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+24
-0
lines changed

‎Doc/library/asyncio-task.rst

Copy file name to clipboardExpand all lines: Doc/library/asyncio-task.rst
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,10 @@ Waiting Primitives
804804
.. versionchanged:: 3.11
805805
Passing coroutine objects to ``wait()`` directly is forbidden.
806806

807+
.. versionchanged:: 3.12
808+
Added support for generators yielding tasks.
809+
810+
807811
.. function:: as_completed(aws, *, timeout=None)
808812

809813
Run :ref:`awaitable objects <asyncio-awaitables>` in the *aws*

‎Doc/whatsnew/3.12.rst

Copy file name to clipboardExpand all lines: Doc/whatsnew/3.12.rst
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ asyncio
241241
:mod:`asyncio` does not support legacy generator-based coroutines.
242242
(Contributed by Kumar Aditya in :gh:`102748`.)
243243

244+
* :func:`asyncio.wait` now accepts generators yielding tasks.
245+
(Contributed by Kumar Aditya in :gh:`78530`.)
246+
244247
inspect
245248
-------
246249

‎Lib/test/test_asyncio/test_tasks.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_tasks.py
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,22 @@ async def foo():
13731373
self.assertEqual(res, 42)
13741374
self.assertAlmostEqual(0.15, loop.time())
13751375

1376+
1377+
def test_wait_generator(self):
1378+
async def func(a):
1379+
return a
1380+
1381+
loop = self.new_test_loop()
1382+
1383+
async def main():
1384+
tasks = (self.new_task(loop, func(i)) for i in range(10))
1385+
done, pending = await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED)
1386+
self.assertEqual(len(done), 10)
1387+
self.assertEqual(len(pending), 0)
1388+
1389+
loop.run_until_complete(main())
1390+
1391+
13761392
def test_as_completed(self):
13771393

13781394
def gen():
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:func:`asyncio.wait` now accepts generators yielding tasks. Patch by Kumar Aditya.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.