Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04356e1

Browse files
committed
Issue #24487: Rename async() -> ensure_future() in asyncio docs.
Patch by Martin Panter.
1 parent 59a3b67 commit 04356e1

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

Doc/library/asyncio-dev.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ To schedule a callback from a different thread, the
9999
:meth:`BaseEventLoop.call_soon_threadsafe` method should be used. Example to
100100
schedule a coroutine from a different thread::
101101

102-
loop.call_soon_threadsafe(asyncio.async, coro_func())
102+
loop.call_soon_threadsafe(asyncio.ensure_future, coro_func())
103103

104104
Most asyncio objects are not thread safe. You should only worry if you access
105105
objects outside the event loop. For example, to cancel a future, don't call
@@ -162,10 +162,10 @@ Detect coroutine objects never scheduled
162162
----------------------------------------
163163

164164
When a coroutine function is called and its result is not passed to
165-
:func:`async` or to the :meth:`BaseEventLoop.create_task` method, the execution
166-
of the coroutine object will never be scheduled which is probably a bug.
167-
:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to :ref:`log a
168-
warning <asyncio-logger>` to detect it.
165+
:func:`ensure_future` or to the :meth:`BaseEventLoop.create_task` method,
166+
the execution of the coroutine object will never be scheduled which is
167+
probably a bug. :ref:`Enable the debug mode of asyncio <asyncio-debug-mode>`
168+
to :ref:`log a warning <asyncio-logger>` to detect it.
169169

170170
Example with the bug::
171171

@@ -184,7 +184,7 @@ Output in debug mode::
184184
File "test.py", line 7, in <module>
185185
test()
186186

187-
The fix is to call the :func:`async` function or the
187+
The fix is to call the :func:`ensure_future` function or the
188188
:meth:`BaseEventLoop.create_task` method with the coroutine object.
189189

190190
.. seealso::

Doc/library/asyncio-eventloop.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Run an event loop
3636
Run until the :class:`Future` is done.
3737

3838
If the argument is a :ref:`coroutine object <coroutine>`, it is wrapped by
39-
:func:`async`.
39+
:func:`ensure_future`.
4040

4141
Return the Future's result, or raise its exception.
4242

Doc/library/asyncio-protocol.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,9 @@ buffer size reaches the low-water mark.
448448
Coroutines and protocols
449449
------------------------
450450

451-
Coroutines can be scheduled in a protocol method using :func:`async`, but there
452-
is no guarantee made about the execution order. Protocols are not aware of
453-
coroutines created in protocol methods and so will not wait for them.
451+
Coroutines can be scheduled in a protocol method using :func:`ensure_future`,
452+
but there is no guarantee made about the execution order. Protocols are not
453+
aware of coroutines created in protocol methods and so will not wait for them.
454454

455455
To have a reliable execution order, use :ref:`stream objects <asyncio-streams>` in a
456456
coroutine with ``yield from``. For example, the :meth:`StreamWriter.drain`

Doc/library/asyncio-task.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ the coroutine object returned by the call doesn't do anything until you
5959
schedule its execution. There are two basic ways to start it running:
6060
call ``await coroutine`` or ``yield from coroutine`` from another coroutine
6161
(assuming the other coroutine is already running!), or schedule its execution
62-
using the :func:`async` function or the :meth:`BaseEventLoop.create_task`
62+
using the :func:`ensure_future` function or the :meth:`BaseEventLoop.create_task`
6363
method.
6464

6565

@@ -85,7 +85,7 @@ Coroutines (and tasks) can only run when the event loop is running.
8585
even if they are plain Python functions returning a :class:`Future`.
8686
This is intentional to have a freedom of tweaking the implementation
8787
of these functions in the future. If such a function is needed to be
88-
used in a callback-style code, wrap its result with :func:`async`.
88+
used in a callback-style code, wrap its result with :func:`ensure_future`.
8989

9090

9191
.. _asyncio-hello-world-coroutine:
@@ -394,7 +394,7 @@ Task
394394
<coroutine>` did not complete. It is probably a bug and a warning is
395395
logged: see :ref:`Pending task destroyed <asyncio-pending-task-destroyed>`.
396396

397-
Don't directly create :class:`Task` instances: use the :func:`async`
397+
Don't directly create :class:`Task` instances: use the :func:`ensure_future`
398398
function or the :meth:`BaseEventLoop.create_task` method.
399399

400400
This class is :ref:`not thread safe <asyncio-multithreading>`.

0 commit comments

Comments
 (0)