Update asyncio documentation · pythoncapi/cpython@530ef2f · GitHub
Skip to content

Commit 530ef2f

Browse files
committed
Update asyncio documentation
- Document the new create_task() method - "Hide" the Task class: point to the create_task() method for interoperability - Rewrite the documentation of the Task class - Document the "Pending task destroyed" - Update output in debug mode of examples in the dev section - Replace Task() with create_task() in examples
1 parent 896a25a commit 530ef2f

4 files changed

Lines changed: 131 additions & 49 deletions

File tree

Doc/library/asyncio-dev.rst

Lines changed: 66 additions & 29 deletions

Doc/library/asyncio-eventloop.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ Run an event loop
102102

103103
Run until the :class:`Future` is done.
104104

105-
If the argument is a :ref:`coroutine <coroutine>`, it is wrapped
106-
in a :class:`Task`.
105+
If the argument is a :ref:`coroutine object <coroutine>`, it is wrapped by
106+
:func:`async`.
107107

108108
Return the Future's result, or raise its exception.
109109

@@ -205,6 +205,25 @@ a different clock than :func:`time.time`.
205205
The :func:`asyncio.sleep` function.
206206

207207

208+
Coroutines
209+
----------
210+
211+
.. method:: BaseEventLoop.create_task(coro)
212+
213+
Schedule the execution of a :ref:`coroutine object <coroutine>`: wrap it in
214+
a future. Return a :class:`Task` object.
215+
216+
Third-party event loops can use their own subclass of :class:`Task` for
217+
interoperability. In this case, the result type is a subclass of
218+
:class:`Task`.
219+
220+
.. seealso::
221+
222+
The :meth:`async` function.
223+
224+
.. versionadded:: 3.4.2
225+
226+
208227
Creating connections
209228
--------------------
210229

Doc/library/asyncio-stream.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ Stream functions
4141
:class:`StreamReader` object, while *client_writer* is a
4242
:class:`StreamWriter` object. This parameter can either be a plain callback
4343
function or a :ref:`coroutine function <coroutine>`; if it is a coroutine
44-
function, it will be automatically converted into a :class:`Task`.
44+
function, it will be automatically wrapped in a future using the
45+
:meth:`BaseEventLoop.create_task` method.
4546

4647
The rest of the arguments are all the usual arguments to
4748
:meth:`~BaseEventLoop.create_server()` except *protocol_factory*; most

Doc/library/asyncio-task.rst

Lines changed: 42 additions & 17 deletions

0 commit comments

Comments
 (0)