ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](asyncio-task.xhtml "协程与任务") | - [上一页](ipc.xhtml "网络和进程间通信") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - [网络和进程间通信](ipc.xhtml) » - $('.inline-search').show(0); | # [`asyncio`](#module-asyncio "asyncio: Asynchronous I/O.") --- 异步 I/O - - - - - - Hello World! ``` import asyncio async def main(): print('Hello ...') await asyncio.sleep(1) print('... World!') # Python 3.7+ asyncio.run(main()) ``` asyncio 是用来编写 **并发** 代码的库,使用 **async/await** 语法。 asyncio 被用作多个提供高性能 Python 异步框架的基础,包括网络和网站服务,数据库连接库,分布式任务队列等等。 asyncio 往往是构建 IO 密集型和高层级 **结构化** 网络代码的最佳选择。 asyncio 提供一组 **高层级** API 用于: - 并发地 [运行 Python 协程](asyncio-task.xhtml#coroutine) 并对其执行过程实现完全控制; - 执行 [网络 IO 和 IPC](asyncio-stream.xhtml#asyncio-streams); - 控制 [子进程](asyncio-subprocess.xhtml#asyncio-subprocess); - 通过 [队列](asyncio-queue.xhtml#asyncio-queues) 实现分布式任务; - [同步](asyncio-sync.xhtml#asyncio-sync) 并发代码; 此外,还有一些 **低层级** API 以支持 *库和框架的开发者* 实现: - 创建和管理 [事件循环](asyncio-eventloop.xhtml#asyncio-event-loop),以提供异步 API 用于 [`网络化`](asyncio-eventloop.xhtml#asyncio.loop.create_server "asyncio.loop.create_server"), 运行 [`子进程`](asyncio-eventloop.xhtml#asyncio.loop.subprocess_exec "asyncio.loop.subprocess_exec"),处理 [`OS 信号`](asyncio-eventloop.xhtml#asyncio.loop.add_signal_handler "asyncio.loop.add_signal_handler") 等等; - 使用 [transports](asyncio-protocol.xhtml#asyncio-transports-protocols) 实现高效率协议; - 通过 async/await 语法 [桥接](asyncio-future.xhtml#asyncio-futures) 基于回调的库和代码。 参考引用 高层级 API - [协程与任务](asyncio-task.xhtml) - [流](asyncio-stream.xhtml) - [Synchronization Primitives](asyncio-sync.xhtml) - [子进程](asyncio-subprocess.xhtml) - [队列集](asyncio-queue.xhtml) - [异常](asyncio-exceptions.xhtml) 低层级 API - [事件循环](asyncio-eventloop.xhtml) - [期程](asyncio-future.xhtml) - [传输和协议](asyncio-protocol.xhtml) - [策略](asyncio-policy.xhtml) - [平台支持](asyncio-platforms.xhtml) 指南与教程 - [高级API索引](asyncio-api-index.xhtml) - [底层API目录](asyncio-llapi-index.xhtml) - [用 asyncio 开发](asyncio-dev.xhtml) ### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](asyncio-task.xhtml "协程与任务") | - [上一页](ipc.xhtml "网络和进程间通信") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - [网络和进程间通信](ipc.xhtml) » - $('.inline-search').show(0); | © [版权所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 软件基金会是一个非盈利组织。 [请捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [发现了问题](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 创建。