asyncio doc: replace "coroutine" with "coroutine object" or "coroutine function"

This commit is contained in:
Victor Stinner 2014-01-16 19:30:21 +01:00
parent db39a0da0c
commit 59759ff234
4 changed files with 41 additions and 39 deletions

View File

@ -158,7 +158,7 @@ Creating connections
*port*. *protocol_factory* must be a callable returning a *port*. *protocol_factory* must be a callable returning a
:ref:`protocol <protocol>` instance. :ref:`protocol <protocol>` instance.
This method returns a :ref:`coroutine <coroutine>` which will try to This method returns a :ref:`coroutine object <coroutine>` which will try to
establish the connection in the background. When successful, the establish the connection in the background. When successful, the
coroutine returns a ``(transport, protocol)`` pair. coroutine returns a ``(transport, protocol)`` pair.
@ -219,7 +219,7 @@ Creating listening connections
.. method:: BaseEventLoop.create_server(protocol_factory, host=None, port=None, \*, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None) .. method:: BaseEventLoop.create_server(protocol_factory, host=None, port=None, \*, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None)
A :ref:`coroutine <coroutine>` which creates a TCP server bound to host and A :ref:`coroutine function <coroutine>` which creates a TCP server bound to host and
port. port.
The return value is a :class:`AbstractServer` object which can be used to stop The return value is a :class:`AbstractServer` object which can be used to stop
@ -249,13 +249,13 @@ Creating listening connections
expire. If not specified will automatically be set to True on expire. If not specified will automatically be set to True on
UNIX. UNIX.
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
.. method:: BaseEventLoop.create_datagram_endpoint(protocol_factory, local_addr=None, remote_addr=None, \*, family=0, proto=0, flags=0) .. method:: BaseEventLoop.create_datagram_endpoint(protocol_factory, local_addr=None, remote_addr=None, \*, family=0, proto=0, flags=0)
Create datagram connection. Create datagram connection.
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
@ -280,7 +280,7 @@ Run subprocesses asynchronously using the :mod:`subprocess` module.
XXX XXX
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
See the constructor of the :class:`subprocess.Popen` class for parameters. See the constructor of the :class:`subprocess.Popen` class for parameters.
@ -288,7 +288,7 @@ Run subprocesses asynchronously using the :mod:`subprocess` module.
XXX XXX
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
See the constructor of the :class:`subprocess.Popen` class for parameters. See the constructor of the :class:`subprocess.Popen` class for parameters.
@ -301,7 +301,7 @@ Run subprocesses asynchronously using the :mod:`subprocess` module.
Return pair (transport, protocol), where transport support Return pair (transport, protocol), where transport support
:class:`ReadTransport` interface. :class:`ReadTransport` interface.
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
.. method:: BaseEventLoop.connect_write_pipe(protocol_factory, pipe) .. method:: BaseEventLoop.connect_write_pipe(protocol_factory, pipe)
@ -312,7 +312,7 @@ Run subprocesses asynchronously using the :mod:`subprocess` module.
Return pair (transport, protocol), where transport support Return pair (transport, protocol), where transport support
:class:`WriteTransport` interface. :class:`WriteTransport` interface.
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
Executor Executor

View File

@ -320,19 +320,19 @@ StreamReader
XXX XXX
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
.. method:: readline() .. method:: readline()
XXX XXX
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
.. method:: readexactly(n) .. method:: readexactly(n)
XXX XXX
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
@ -550,7 +550,7 @@ Network functions
:class:`StreamReaderProtocol` classes, just copy the code -- there's really :class:`StreamReaderProtocol` classes, just copy the code -- there's really
nothing special here except some convenience.) nothing special here except some convenience.)
This function returns a :ref:`coroutine <coroutine>`. This function returns a :ref:`coroutine object <coroutine>`.
.. function:: start_server(client_connected_cb, host=None, port=None, *, loop=None, limit=_DEFAULT_LIMIT, **kwds) .. function:: start_server(client_connected_cb, host=None, port=None, *, loop=None, limit=_DEFAULT_LIMIT, **kwds)
@ -560,8 +560,8 @@ Network functions
*client_reader*, *client_writer*. *client_reader* is a *client_reader*, *client_writer*. *client_reader* is a
:class:`StreamReader` object, while *client_writer* is a :class:`StreamReader` object, while *client_writer* is a
:class:`StreamWriter` object. This parameter can either be a plain callback :class:`StreamWriter` object. This parameter can either be a plain callback
function or a :ref:`coroutine <coroutine>`; if it is a coroutine, it will be function or a :ref:`coroutine function <coroutine>`; if it is a coroutine
automatically converted into a :class:`Task`. function, it will be automatically converted into a :class:`Task`.
The rest of the arguments are all the usual arguments to The rest of the arguments are all the usual arguments to
:meth:`~BaseEventLoop.create_server()` except *protocol_factory*; most :meth:`~BaseEventLoop.create_server()` except *protocol_factory*; most
@ -576,7 +576,7 @@ Network functions
The return value is the same as :meth:`~BaseEventLoop.create_server()`, i.e. The return value is the same as :meth:`~BaseEventLoop.create_server()`, i.e.
a :class:`AbstractServer` object which can be used to stop the service. a :class:`AbstractServer` object which can be used to stop the service.
This function returns a :ref:`coroutine <coroutine>`. This function returns a :ref:`coroutine object <coroutine>`.
Protocol example: TCP echo server and client Protocol example: TCP echo server and client

View File

@ -70,7 +70,7 @@ Locks
This method blocks until the lock is unlocked, then sets it to locked and This method blocks until the lock is unlocked, then sets it to locked and
returns ``True``. returns ``True``.
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
.. method:: release() .. method:: release()
@ -118,7 +118,7 @@ Locks
Otherwise, block until another coroutine calls :meth:`set` to set the Otherwise, block until another coroutine calls :meth:`set` to set the
flag to true, then return ``True``. flag to true, then return ``True``.
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
.. class:: Condition(\*, loop=None) .. class:: Condition(\*, loop=None)
@ -166,7 +166,7 @@ Locks
condition variable in another coroutine. Once awakened, it re-acquires condition variable in another coroutine. Once awakened, it re-acquires
the lock and returns ``True``. the lock and returns ``True``.
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
.. method:: wait_for(predicate) .. method:: wait_for(predicate)
@ -175,7 +175,7 @@ Locks
The predicate should be a callable which result will be interpreted as a The predicate should be a callable which result will be interpreted as a
boolean value. The final predicate value is the return value. boolean value. The final predicate value is the return value.
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
Semaphores Semaphores
@ -205,7 +205,7 @@ Semaphores
until some other coroutine has called :meth:`release` to make it larger until some other coroutine has called :meth:`release` to make it larger
than ``0``, and then return ``True``. than ``0``, and then return ``True``.
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
.. method:: locked() .. method:: locked()
@ -261,7 +261,7 @@ Queues
If you yield from :meth:`get()`, wait until a item is available. If you yield from :meth:`get()`, wait until a item is available.
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
.. method:: get_nowait() .. method:: get_nowait()
@ -277,7 +277,7 @@ Queues
If you yield from ``put()``, wait until a free slot is available before If you yield from ``put()``, wait until a free slot is available before
adding item. adding item.
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
.. method:: put_nowait(item) .. method:: put_nowait(item)
@ -323,7 +323,7 @@ Queues
it is complete. When the count of unfinished tasks drops to zero, it is complete. When the count of unfinished tasks drops to zero,
:meth:`join` unblocks. :meth:`join` unblocks.
This method returns a :ref:`coroutine <coroutine>`. This method returns a :ref:`coroutine object <coroutine>`.
.. method:: task_done() .. method:: task_done()

View File

@ -19,7 +19,7 @@ The word "coroutine", like the word "generator", is used for two
different (though related) concepts: different (though related) concepts:
- The function that defines a coroutine (a function definition - The function that defines a coroutine (a function definition
decorated with ``asyncio.coroutine``). If disambiguation is needed decorated with ``@asyncio.coroutine``). If disambiguation is needed
we will call this a *coroutine function*. we will call this a *coroutine function*.
- The object obtained by calling a coroutine function. This object - The object obtained by calling a coroutine function. This object
@ -117,7 +117,7 @@ Sequence diagram of the example:
:align: center :align: center
The "Task" is created by the :meth:`BaseEventLoop.run_until_complete` method The "Task" is created by the :meth:`BaseEventLoop.run_until_complete` method
when it gets a coroutine instead of a task. when it gets a coroutine object instead of a task.
The diagram shows the control flow, it does not describe exactly how things The diagram shows the control flow, it does not describe exactly how things
work internally. For example, the sleep coroutine creates an internal future work internally. For example, the sleep coroutine creates an internal future
@ -219,7 +219,8 @@ Future
Example: Future with run_until_complete() Example: Future with run_until_complete()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Example combining a :class:`Future` and a :ref:`coroutine <coroutine>`:: Example combining a :class:`Future` and a :ref:`coroutine function
<coroutine>`::
import asyncio import asyncio
@ -234,8 +235,8 @@ Example combining a :class:`Future` and a :ref:`coroutine <coroutine>`::
loop.run_until_complete(future) loop.run_until_complete(future)
print(future.result()) print(future.result())
The coroutine is responsible of the computation (which takes 1 second) and The coroutine function is responsible of the computation (which takes 1 second)
it stores the result into the future. The and it stores the result into the future. The
:meth:`~BaseEventLoop.run_until_complete` method waits for the completion of :meth:`~BaseEventLoop.run_until_complete` method waits for the completion of
the future. the future.
@ -273,9 +274,9 @@ In this example, the future is responsible to display the result and to stop
the loop. the loop.
.. note:: .. note::
The coroutine is only executed when the event loop starts running, so it is The "slow_operation" coroutine object is only executed when the event loop
possible to add a "done callback" to the future after creating the task starts running, so it is possible to add a "done callback" to the future
scheduling the coroutine. after creating the task scheduling the coroutine object.
@ -284,7 +285,7 @@ Task
.. class:: Task(coro, \*, loop=None) .. class:: Task(coro, \*, loop=None)
A coroutine wrapped in a :class:`Future`. Subclass of :class:`Future`. A coroutine object wrapped in a :class:`Future`. Subclass of :class:`Future`.
.. classmethod:: all_tasks(loop=None) .. classmethod:: all_tasks(loop=None)
@ -392,13 +393,14 @@ Task functions
.. function:: async(coro_or_future, \*, loop=None) .. function:: async(coro_or_future, \*, loop=None)
Wrap a :ref:`coroutine <coroutine>` in a future. Wrap a :ref:`coroutine object <coroutine>` in a future.
If the argument is a :class:`Future`, it is returned directly. If the argument is a :class:`Future`, it is returned directly.
.. function:: gather(\*coros_or_futures, loop=None, return_exceptions=False) .. function:: gather(\*coros_or_futures, loop=None, return_exceptions=False)
Return a future aggregating results from the given coroutines or futures. Return a future aggregating results from the given coroutine objects or
futures.
All futures must share the same event loop. If all the tasks are done All futures must share the same event loop. If all the tasks are done
successfully, the returned future's result is the list of results (in the successfully, the returned future's result is the list of results (in the
@ -416,8 +418,8 @@ Task functions
.. function:: sleep(delay, result=None, \*, loop=None) .. function:: sleep(delay, result=None, \*, loop=None)
Create a :ref:`coroutine <coroutine>` that completes after a given time Create a :ref:`coroutine object <coroutine>` that completes after a given
(in seconds). time (in seconds).
.. function:: shield(arg, \*, loop=None) .. function:: shield(arg, \*, loop=None)
@ -448,8 +450,8 @@ Task functions
.. function:: wait(futures, \*, loop=None, timeout=None, return_when=ALL_COMPLETED) .. function:: wait(futures, \*, loop=None, timeout=None, return_when=ALL_COMPLETED)
Wait for the Futures and coroutines given by the sequence *futures* to Wait for the Futures and coroutine objects given by the sequence *futures*
complete. Coroutines will be wrapped in Tasks. Returns two sets of to complete. Coroutines will be wrapped in Tasks. Returns two sets of
:class:`Future`: (done, pending). :class:`Future`: (done, pending).
*timeout* can be used to control the maximum number of seconds to wait before *timeout* can be used to control the maximum number of seconds to wait before
@ -477,7 +479,7 @@ Task functions
| | futures finish or are cancelled. | | | futures finish or are cancelled. |
+-----------------------------+----------------------------------------+ +-----------------------------+----------------------------------------+
This function returns a :ref:`coroutine <coroutine>`. This function returns a :ref:`coroutine object <coroutine>`.
Usage:: Usage::