Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
996859a9
Commit
996859a9
authored
Sep 25, 2018
by
Yury Selivanov
Committed by
GitHub
Sep 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-34790: [docs] Passing coroutines to asyncio.wait() can be confusing. (GH-9543)
parent
22ef31d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
4 deletions
+37
-4
Doc/library/asyncio-task.rst
Doc/library/asyncio-task.rst
+36
-4
Misc/NEWS.d/next/Documentation/2018-09-24-12-47-08.bpo-34790.G2KXIH.rst
...xt/Documentation/2018-09-24-12-47-08.bpo-34790.G2KXIH.rst
+1
-0
No files found.
Doc/library/asyncio-task.rst
View file @
996859a9
...
...
@@ -472,14 +472,20 @@ Waiting Primitives
return_when=ALL_COMPLETED)
Run :ref:`awaitable objects <asyncio-awaitables>` in the *aws*
se
quence
concurrently and block until the condition specified
se
t
concurrently and block until the condition specified
by *return_when*.
If any awaitable in *aws* is a coroutine, it is automatically
scheduled as a Task.
scheduled as a Task. Passing coroutines objects to
``wait()`` directly is deprecated as it leads to
:ref:`confusing behavior <asyncio_example_wait_coroutine>`.
Returns two sets of Tasks/Futures: ``(done, pending)``.
Usage::
done, pending = await asyncio.wait(aws)
The *loop* argument is deprecated and scheduled for removal
in Python 4.0.
...
...
@@ -514,9 +520,35 @@ Waiting Primitives
Unlike :func:`~asyncio.wait_for`, ``wait()`` does not cancel the
futures when a timeout occurs.
Usage::
.. _asyncio_example_wait_coroutine:
.. note::
done, pending = await asyncio.wait(aws)
``wait()`` schedules coroutines as Tasks automatically and later
returns those implicitly created Task objects in ``(done, pending)``
sets. Therefore the following code won't work as expected::
async def foo():
return 42
coro = foo()
done, pending = await asyncio.wait({coro})
if coro in done:
# This branch will never be run!
Here is how the above snippet can be fixed::
async def foo():
return 42
task = asyncio.create_task(foo())
done, pending = await asyncio.wait({task})
if task in done:
# Everything will work as expected now.
Passing coroutine objects to ``wait()`` directly is
deprecated.
.. function:: as_completed(aws, \*, loop=None, timeout=None)
...
...
Misc/NEWS.d/next/Documentation/2018-09-24-12-47-08.bpo-34790.G2KXIH.rst
0 → 100644
View file @
996859a9
Document how passing coroutines to asyncio.wait() can be confusing.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment