asyncio
— Asynchronous异步 I/O¶
asyncio is a library to write concurrent code using the async/await syntax.是一个使用异步/等待语法编写并发代码的库。
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.用作提供高性能网络和web服务器、数据库连接库、分布式任务队列等的多个Python异步框架的基础。
asyncio is often a perfect fit for IO-bound and high-level structured network code.通常非常适合IO绑定和高级结构化网络代码。
asyncio provides a set of high-level APIs to:提供一组高级API,用于:
run Python coroutines concurrently and have full control over their execution;并发运行Python协程,并完全控制其执行;perform network IO and IPC;实施网络IO和IPC;control subprocesses;控制子进程;synchronize concurrent code;同步并发代码;
Additionally, there are low-level APIs for library and framework developers to:此外,库和框架开发人员还可以使用低级API:
create and manage event loops, which provide asynchronous APIs for创建和管理事件循环,为networking
, runningsubprocesses
, handlingOS signals
, etc;networking
、运行subprocesses
、处理OS signals
等提供异步API;implement efficient protocols using transports;使用传输实现高效协议;bridge callback-based libraries and code with async/await syntax.使用异步/等待语法桥接基于回调的库和代码。
Reference参考
High-level APIs高级API
Low-level APIs低级API
Guides and Tutorials指南和教程
Note
The source code for asyncio can be found in Lib/asyncio/.asyncio的源代码可以在Lib/asyncio/中找到。