blob: 2c8ccbb390f01b83efe1c510c68a515dc497699b [file] [log] [blame]
Yury Selivanov3faaa882018-09-14 13:32:07 -07001:mod:`asyncio` --- Asynchronous I/O
2===================================
Guido van Rossum7a465642013-11-22 11:47:22 -08003
4.. module:: asyncio
Yury Selivanov3faaa882018-09-14 13:32:07 -07005 :synopsis: Asynchronous I/O.
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04006
Guido van Rossumf8d0ff92013-11-22 16:53:25 -08007--------------
Guido van Rossum7a465642013-11-22 11:47:22 -08008
Yury Selivanov3faaa882018-09-14 13:32:07 -07009.. TODO: rewrite the introduction section
10
Antoine Pitroubba86822013-11-23 00:34:26 +010011This module provides infrastructure for writing single-threaded concurrent
12code using coroutines, multiplexing I/O access over sockets and other
13resources, running network clients and servers, and other related primitives.
Antoine Pitroubba86822013-11-23 00:34:26 +010014Here is a more detailed list of the package contents:
15
Victor Stinner9592edb2014-02-02 15:03:02 +010016* a pluggable :ref:`event loop <asyncio-event-loop>` with various system-specific
Antoine Pitroubba86822013-11-23 00:34:26 +010017 implementations;
18
Victor Stinner9592edb2014-02-02 15:03:02 +010019* :ref:`transport <asyncio-transport>` and :ref:`protocol <asyncio-protocol>` abstractions
Georg Brandlb7354a62014-10-29 10:57:37 +010020 (similar to those in `Twisted <https://twistedmatrix.com/trac/>`_);
Antoine Pitroubba86822013-11-23 00:34:26 +010021
22* concrete support for TCP, UDP, SSL, subprocess pipes, delayed calls, and
23 others (some may be system-dependent);
24
Brian Curtina1afeec2014-02-08 18:36:14 -060025* a :class:`Future` class that mimics the one in the :mod:`concurrent.futures`
Victor Stinner99c2ab42013-12-03 19:17:25 +010026 module, but adapted for use with the event loop;
Antoine Pitroubba86822013-11-23 00:34:26 +010027
28* coroutines and tasks based on ``yield from`` (:PEP:`380`), to help write
29 concurrent code in a sequential fashion;
30
Eli Benderskyb73c8332014-02-09 06:07:47 -080031* cancellation support for :class:`Future`\s and coroutines;
Antoine Pitroubba86822013-11-23 00:34:26 +010032
Victor Stinner9592edb2014-02-02 15:03:02 +010033* :ref:`synchronization primitives <asyncio-sync>` for use between coroutines in
Antoine Pitroubba86822013-11-23 00:34:26 +010034 a single thread, mimicking those in the :mod:`threading` module;
35
Guido van Rossumf0f5d382013-11-22 15:45:02 -080036* an interface for passing work off to a threadpool, for times when
37 you absolutely, positively have to use a library that makes blocking
38 I/O calls.
39
Victor Stinner532c69a2015-02-25 14:23:51 +010040Asynchronous programming is more complex than classical "sequential"
41programming: see the :ref:`Develop with asyncio <asyncio-dev>` page which lists
42common traps and explains how to avoid them. :ref:`Enable the debug mode
43<asyncio-debug-mode>` during development to detect common issues.
44
Yury Selivanov3faaa882018-09-14 13:32:07 -070045High-level APIs:
Antoine Pitroubba86822013-11-23 00:34:26 +010046
Victor Stinnerea3183f2013-12-03 01:08:00 +010047.. toctree::
Yury Selivanov3faaa882018-09-14 13:32:07 -070048 :maxdepth: 1
49
50 asyncio-task.rst
51 asyncio-stream.rst
52 asyncio-sync.rst
53 asyncio-subprocess.rst
54 asyncio-queue.rst
55 asyncio-exceptions.rst
56
57Low-level APIs:
58
59.. toctree::
60 :maxdepth: 1
Antoine Pitroubba86822013-11-23 00:34:26 +010061
Victor Stinnerea3183f2013-12-03 01:08:00 +010062 asyncio-eventloop.rst
Yury Selivanov3faaa882018-09-14 13:32:07 -070063 asyncio-future.rst
64 asyncio-protocol.rst
Yury Selivanov7c7605f2018-09-11 09:54:40 -070065 asyncio-policy.rst
66 asyncio-platforms.rst
Yury Selivanov3faaa882018-09-14 13:32:07 -070067
68Guides and Tutorials:
69
70.. toctree::
71 :maxdepth: 1
72
Victor Stinnerdb39a0d2014-01-16 18:58:01 +010073 asyncio-dev.rst
Yury Selivanov3faaa882018-09-14 13:32:07 -070074
Antoine Pitroubba86822013-11-23 00:34:26 +010075
Victor Stinner85a2be72013-12-03 15:04:36 +010076.. seealso::
77
Yury Selivanov3faaa882018-09-14 13:32:07 -070078 The :mod:`asyncio` module was proposed in :PEP:`3156`.
79 Since the acceptance of the PEP many new APIs were added and many
80 original APIs were altered. The PEP should be treated as a
81 historical document.