| 
									
										
										
										
											2018-09-14 13:32:07 -07:00
										 |  |  | :mod:`asyncio` --- Asynchronous I/O
 | 
					
						
							|  |  |  | ===================================
 | 
					
						
							| 
									
										
										
										
											2013-11-22 11:47:22 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. module:: asyncio
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:32:07 -07:00
										 |  |  |    :synopsis: Asynchronous I/O.
 | 
					
						
							| 
									
										
										
										
											2016-06-11 15:02:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-22 16:53:25 -08:00
										 |  |  | --------------
 | 
					
						
							| 
									
										
										
										
											2013-11-22 11:47:22 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | asyncio is a library to write **concurrent** code using
 | 
					
						
							|  |  |  | **async/await** syntax.
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:32:07 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | asyncio is used as a foundation for multiple Python asynchronous
 | 
					
						
							|  |  |  | frameworks that provide high-performance network and web-servers,
 | 
					
						
							|  |  |  | database connection libraries, distributed task queues, etc.
 | 
					
						
							| 
									
										
										
										
											2013-11-23 00:34:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | asyncio is often a perfect fit for IO-bound and high-level
 | 
					
						
							|  |  |  | **structured** network code.
 | 
					
						
							| 
									
										
										
										
											2013-11-23 00:34:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | asyncio provides a set of **high-level** APIs to:
 | 
					
						
							| 
									
										
										
										
											2013-11-23 00:34:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | * :ref:`run Python coroutines <coroutine>` concurrently and
 | 
					
						
							|  |  |  |   have full control over their execution;
 | 
					
						
							| 
									
										
										
										
											2013-11-23 00:34:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | * perform :ref:`network IO and IPC <asyncio-streams>`;
 | 
					
						
							| 
									
										
										
										
											2013-11-23 00:34:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | * control :ref:`subprocesses <asyncio-subprocess>`;
 | 
					
						
							| 
									
										
										
										
											2013-11-23 00:34:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | * distribute tasks via :ref:`queues <asyncio-queues>`;
 | 
					
						
							| 
									
										
										
										
											2013-11-23 00:34:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | * :ref:`synchronize <asyncio-sync>` concurrent code;
 | 
					
						
							| 
									
										
										
										
											2013-11-23 00:34:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | as well as **low-level** APIs for *library and framework developers* to:
 | 
					
						
							| 
									
										
										
										
											2013-11-22 15:45:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | * create and manage :ref:`event loops <asyncio-event-loop>`, which
 | 
					
						
							|  |  |  |   provide asynchronous APIs for networking, subprocesses, OS signals,
 | 
					
						
							|  |  |  |   etc;
 | 
					
						
							| 
									
										
										
										
											2015-02-25 14:23:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | * implement efficient protocols using
 | 
					
						
							|  |  |  |   :ref:`transports <asyncio-transports-protocols>`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | * :ref:`bridge <asyncio-futures>` callback-based libraries and code
 | 
					
						
							|  |  |  |   with async/await syntax.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 15:11:24 -07:00
										 |  |  | Reference
 | 
					
						
							|  |  |  | ---------
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. rubric:: High-level APIs
 | 
					
						
							| 
									
										
										
										
											2013-11-23 00:34:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 01:08:00 +01:00
										 |  |  | .. toctree::
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:32:07 -07:00
										 |  |  |    :maxdepth: 1
 | 
					
						
							| 
									
										
										
										
											2013-12-03 01:08:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |    asyncio-task.rst
 | 
					
						
							| 
									
										
										
										
											2014-01-23 11:05:01 +01:00
										 |  |  |    asyncio-stream.rst
 | 
					
						
							| 
									
										
										
										
											2013-12-03 01:08:00 +01:00
										 |  |  |    asyncio-sync.rst
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:32:07 -07:00
										 |  |  |    asyncio-subprocess.rst
 | 
					
						
							| 
									
										
										
										
											2015-02-25 13:55:43 +01:00
										 |  |  |    asyncio-queue.rst
 | 
					
						
							| 
									
										
										
										
											2018-09-11 09:54:40 -07:00
										 |  |  |    asyncio-exceptions.rst
 | 
					
						
							| 
									
										
										
										
											2013-11-23 00:34:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | .. rubric:: Low-level APIs
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:32:07 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. toctree::
 | 
					
						
							|  |  |  |    :maxdepth: 1
 | 
					
						
							| 
									
										
										
										
											2013-12-03 15:04:36 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:32:07 -07:00
										 |  |  |    asyncio-eventloop.rst
 | 
					
						
							|  |  |  |    asyncio-future.rst
 | 
					
						
							|  |  |  |    asyncio-protocol.rst
 | 
					
						
							|  |  |  |    asyncio-policy.rst
 | 
					
						
							|  |  |  |    asyncio-platforms.rst
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 14:57:39 -07:00
										 |  |  | .. rubric:: Guides and Tutorials
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:32:07 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. toctree::
 | 
					
						
							|  |  |  |    :maxdepth: 1
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 15:11:24 -07:00
										 |  |  |    asyncio-api-index.rst
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:32:07 -07:00
										 |  |  |    asyncio-dev.rst
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. seealso::
 | 
					
						
							| 
									
										
										
										
											2013-12-03 15:04:36 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 13:32:07 -07:00
										 |  |  |    The :mod:`asyncio` module was proposed in :PEP:`3156`.
 | 
					
						
							|  |  |  |    Since the acceptance of the PEP many new APIs were added and many
 | 
					
						
							|  |  |  |    original APIs were altered.  The PEP should be treated as a
 | 
					
						
							|  |  |  |    historical document.
 |