Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame^] | 1 | :mod:`asyncio` --- Asynchronous I/O |
| 2 | =================================== |
Guido van Rossum | 7a46564 | 2013-11-22 11:47:22 -0800 | [diff] [blame] | 3 | |
| 4 | .. module:: asyncio |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame^] | 5 | :synopsis: Asynchronous I/O. |
Terry Jan Reedy | fa089b9 | 2016-06-11 15:02:54 -0400 | [diff] [blame] | 6 | |
Guido van Rossum | f8d0ff9 | 2013-11-22 16:53:25 -0800 | [diff] [blame] | 7 | -------------- |
Guido van Rossum | 7a46564 | 2013-11-22 11:47:22 -0800 | [diff] [blame] | 8 | |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame^] | 9 | .. TODO: rewrite the introduction section |
| 10 | |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 11 | This module provides infrastructure for writing single-threaded concurrent |
| 12 | code using coroutines, multiplexing I/O access over sockets and other |
| 13 | resources, running network clients and servers, and other related primitives. |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 14 | Here is a more detailed list of the package contents: |
| 15 | |
Victor Stinner | 9592edb | 2014-02-02 15:03:02 +0100 | [diff] [blame] | 16 | * a pluggable :ref:`event loop <asyncio-event-loop>` with various system-specific |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 17 | implementations; |
| 18 | |
Victor Stinner | 9592edb | 2014-02-02 15:03:02 +0100 | [diff] [blame] | 19 | * :ref:`transport <asyncio-transport>` and :ref:`protocol <asyncio-protocol>` abstractions |
Georg Brandl | b7354a6 | 2014-10-29 10:57:37 +0100 | [diff] [blame] | 20 | (similar to those in `Twisted <https://twistedmatrix.com/trac/>`_); |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 21 | |
| 22 | * concrete support for TCP, UDP, SSL, subprocess pipes, delayed calls, and |
| 23 | others (some may be system-dependent); |
| 24 | |
Brian Curtin | a1afeec | 2014-02-08 18:36:14 -0600 | [diff] [blame] | 25 | * a :class:`Future` class that mimics the one in the :mod:`concurrent.futures` |
Victor Stinner | 99c2ab4 | 2013-12-03 19:17:25 +0100 | [diff] [blame] | 26 | module, but adapted for use with the event loop; |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 27 | |
| 28 | * coroutines and tasks based on ``yield from`` (:PEP:`380`), to help write |
| 29 | concurrent code in a sequential fashion; |
| 30 | |
Eli Bendersky | b73c833 | 2014-02-09 06:07:47 -0800 | [diff] [blame] | 31 | * cancellation support for :class:`Future`\s and coroutines; |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 32 | |
Victor Stinner | 9592edb | 2014-02-02 15:03:02 +0100 | [diff] [blame] | 33 | * :ref:`synchronization primitives <asyncio-sync>` for use between coroutines in |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 34 | a single thread, mimicking those in the :mod:`threading` module; |
| 35 | |
Guido van Rossum | f0f5d38 | 2013-11-22 15:45:02 -0800 | [diff] [blame] | 36 | * 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 Stinner | 532c69a | 2015-02-25 14:23:51 +0100 | [diff] [blame] | 40 | Asynchronous programming is more complex than classical "sequential" |
| 41 | programming: see the :ref:`Develop with asyncio <asyncio-dev>` page which lists |
| 42 | common traps and explains how to avoid them. :ref:`Enable the debug mode |
| 43 | <asyncio-debug-mode>` during development to detect common issues. |
| 44 | |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame^] | 45 | High-level APIs: |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 46 | |
Victor Stinner | ea3183f | 2013-12-03 01:08:00 +0100 | [diff] [blame] | 47 | .. toctree:: |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame^] | 48 | :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 | |
| 57 | Low-level APIs: |
| 58 | |
| 59 | .. toctree:: |
| 60 | :maxdepth: 1 |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 61 | |
Victor Stinner | ea3183f | 2013-12-03 01:08:00 +0100 | [diff] [blame] | 62 | asyncio-eventloop.rst |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame^] | 63 | asyncio-future.rst |
| 64 | asyncio-protocol.rst |
Yury Selivanov | 7c7605f | 2018-09-11 09:54:40 -0700 | [diff] [blame] | 65 | asyncio-policy.rst |
| 66 | asyncio-platforms.rst |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame^] | 67 | |
| 68 | Guides and Tutorials: |
| 69 | |
| 70 | .. toctree:: |
| 71 | :maxdepth: 1 |
| 72 | |
Victor Stinner | db39a0d | 2014-01-16 18:58:01 +0100 | [diff] [blame] | 73 | asyncio-dev.rst |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame^] | 74 | |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 75 | |
Victor Stinner | 85a2be7 | 2013-12-03 15:04:36 +0100 | [diff] [blame] | 76 | .. seealso:: |
| 77 | |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame^] | 78 | 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. |