*port*. *protocol_factory* must be a callable returning a
: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
coroutine returns a ``(transport, protocol)`` pair.
.. 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.
The return value is a :class:`AbstractServer` object which can be used to stop
expire. If not specified will automatically be set to True on
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)
Create datagram connection.
- This method returns a :ref:`coroutine <coroutine>`.
+ This method returns a :ref:`coroutine object <coroutine>`.
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.
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.
Return pair (transport, protocol), where transport support
: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)
Return pair (transport, protocol), where transport support
:class:`WriteTransport` interface.
- This method returns a :ref:`coroutine <coroutine>`.
+ This method returns a :ref:`coroutine object <coroutine>`.
Executor
XXX
- This method returns a :ref:`coroutine <coroutine>`.
+ This method returns a :ref:`coroutine object <coroutine>`.
.. method:: readline()
XXX
- This method returns a :ref:`coroutine <coroutine>`.
+ This method returns a :ref:`coroutine object <coroutine>`.
.. method:: readexactly(n)
XXX
- This method returns a :ref:`coroutine <coroutine>`.
+ This method returns a :ref:`coroutine object <coroutine>`.
:class:`StreamReaderProtocol` classes, just copy the code -- there's really
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)
*client_reader*, *client_writer*. *client_reader* is a
:class:`StreamReader` object, while *client_writer* is a
: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
- automatically converted into a :class:`Task`.
+ function or a :ref:`coroutine function <coroutine>`; if it is a coroutine
+ function, it will be automatically converted into a :class:`Task`.
The rest of the arguments are all the usual arguments to
:meth:`~BaseEventLoop.create_server()` except *protocol_factory*; most
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.
- This function returns a :ref:`coroutine <coroutine>`.
+ This function returns a :ref:`coroutine object <coroutine>`.
Protocol example: TCP echo server and client
This method blocks until the lock is unlocked, then sets it to locked and
returns ``True``.
- This method returns a :ref:`coroutine <coroutine>`.
+ This method returns a :ref:`coroutine object <coroutine>`.
.. method:: release()
Otherwise, block until another coroutine calls :meth:`set` to set the
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)
condition variable in another coroutine. Once awakened, it re-acquires
the lock and returns ``True``.
- This method returns a :ref:`coroutine <coroutine>`.
+ This method returns a :ref:`coroutine object <coroutine>`.
.. method:: wait_for(predicate)
The predicate should be a callable which result will be interpreted as a
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
until some other coroutine has called :meth:`release` to make it larger
than ``0``, and then return ``True``.
- This method returns a :ref:`coroutine <coroutine>`.
+ This method returns a :ref:`coroutine object <coroutine>`.
.. method:: locked()
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()
If you yield from ``put()``, wait until a free slot is available before
adding item.
- This method returns a :ref:`coroutine <coroutine>`.
+ This method returns a :ref:`coroutine object <coroutine>`.
.. method:: put_nowait(item)
it is complete. When the count of unfinished tasks drops to zero,
:meth:`join` unblocks.
- This method returns a :ref:`coroutine <coroutine>`.
+ This method returns a :ref:`coroutine object <coroutine>`.
.. method:: task_done()
different (though related) concepts:
- 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*.
- The object obtained by calling a coroutine function. This object
:align: center
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
work internally. For example, the sleep coroutine creates an internal future
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
loop.run_until_complete(future)
print(future.result())
-The coroutine is responsible of the computation (which takes 1 second) and
-it stores the result into the future. The
+The coroutine function is responsible of the computation (which takes 1 second)
+and it stores the result into the future. The
:meth:`~BaseEventLoop.run_until_complete` method waits for the completion of
the future.
the loop.
.. note::
- The coroutine is only executed when the event loop starts running, so it is
- possible to add a "done callback" to the future after creating the task
- scheduling the coroutine.
+ The "slow_operation" coroutine object is only executed when the event loop
+ starts running, so it is possible to add a "done callback" to the future
+ after creating the task scheduling the coroutine object.
.. 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)
.. 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.
.. 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
successfully, the returned future's result is the list of results (in the
.. function:: sleep(delay, result=None, \*, loop=None)
- Create a :ref:`coroutine <coroutine>` that completes after a given time
- (in seconds).
+ Create a :ref:`coroutine object <coroutine>` that completes after a given
+ time (in seconds).
.. function:: shield(arg, \*, loop=None)
.. function:: wait(futures, \*, loop=None, timeout=None, return_when=ALL_COMPLETED)
- Wait for the Futures and coroutines given by the sequence *futures* to
- complete. Coroutines will be wrapped in Tasks. Returns two sets of
+ Wait for the Futures and coroutine objects given by the sequence *futures*
+ to complete. Coroutines will be wrapped in Tasks. Returns two sets of
:class:`Future`: (done, pending).
*timeout* can be used to control the maximum number of seconds to wait before
| | futures finish or are cancelled. |
+-----------------------------+----------------------------------------+
- This function returns a :ref:`coroutine <coroutine>`.
+ This function returns a :ref:`coroutine object <coroutine>`.
Usage::