asyncio.rst 2.48 KB
Newer Older
1 2 3 4 5
:mod:`asyncio` -- Asynchronous I/O, event loop, coroutines and tasks
====================================================================

.. module:: asyncio
   :synopsis: Asynchronous I/O, event loop, coroutines and tasks.
6 7 8 9 10 11 12

.. note::

   The asyncio package has been included in the standard library on a
   :term:`provisional basis <provisional package>`. Backwards incompatible
   changes (up to and including removal of the module) may occur if deemed
   necessary by the core developers.
13

14 15
.. versionadded:: 3.4

16 17 18
**Source code:** :source:`Lib/asyncio/`

--------------
19

20 21 22 23 24
This module provides infrastructure for writing single-threaded concurrent
code using coroutines, multiplexing I/O access over sockets and other
resources, running network clients and servers, and other related primitives.
Here is a more detailed list of the package contents:

25
* a pluggable :ref:`event loop <asyncio-event-loop>` with various system-specific
26 27
  implementations;

28
* :ref:`transport <asyncio-transport>` and :ref:`protocol <asyncio-protocol>` abstractions
29
  (similar to those in `Twisted <https://twistedmatrix.com/trac/>`_);
30 31 32 33

* concrete support for TCP, UDP, SSL, subprocess pipes, delayed calls, and
  others (some may be system-dependent);

34
* a :class:`Future` class that mimics the one in the :mod:`concurrent.futures`
35
  module, but adapted for use with the event loop;
36 37 38 39

* coroutines and tasks based on ``yield from`` (:PEP:`380`), to help write
  concurrent code in a sequential fashion;

40
* cancellation support for :class:`Future`\s and coroutines;
41

42
* :ref:`synchronization primitives <asyncio-sync>` for use between coroutines in
43 44
  a single thread, mimicking those in the :mod:`threading` module;

45 46 47 48
* an interface for passing work off to a threadpool, for times when
  you absolutely, positively have to use a library that makes blocking
  I/O calls.

49 50 51 52 53
Asynchronous programming is more complex than classical "sequential"
programming: see the :ref:`Develop with asyncio <asyncio-dev>` page which lists
common traps and explains how to avoid them. :ref:`Enable the debug mode
<asyncio-debug-mode>` during development to detect common issues.

54
Table of contents:
55

56 57 58 59
.. toctree::
   :maxdepth: 3

   asyncio-eventloop.rst
60
   asyncio-eventloops.rst
61 62
   asyncio-task.rst
   asyncio-protocol.rst
63
   asyncio-stream.rst
64
   asyncio-subprocess.rst
65
   asyncio-sync.rst
66
   asyncio-queue.rst
67
   asyncio-dev.rst
68

69 70
.. seealso::

71
   The :mod:`asyncio` module was designed in :PEP:`3156`. For a
72 73
   motivational primer on transports and protocols, see :PEP:`3153`.