Python Asyncio: 完整指南¶
Python Asyncio: The Complete Guide
原文: https://superfastpython.com/python-asyncio/
最新¶
Python 的 Asyncio 提供了基于协程(coroutines)的异步编程(asynchronous programming)。
异步编程是一种流行的编程范式,它允许大量轻量级任务并发运行,与线程相比,其内存开销非常小。
这使得 asyncio 在 Python Web 开发、进行网络调用的 Python API,以及套接字编程的并发性方面非常吸引人且广泛使用。
这本指南提供了 Python Asyncio 的详细且全面的介绍。
一些提示:
让我们开始深入学习。
Python Asyncio provides asynchronous programming with coroutines.
Asynchronous programming is a popular programming paradigm that allows a large number of lightweight tasks to run concurrently with very little memory overhead, compared to threads.
This makes asyncio very attractive and widely used for Python web development, Python APIs that make web calls, and concurrency for socket programming.
This book-length guide provides a detailed and comprehensive walkthrough of Python Asyncio.
Some tips:
- You may want to bookmark this guide and read it over a few sittings.
- You can download a zip of all code used in this guide.
- You can get help, ask a question in the comments or email me.
- You can jump to the topics that interest you via the table of contents (below).
Let’s dive in.
旧版¶
Asyncio 允许我们在 Python 中使用基于协程的并发的异步编程。
尽管 asyncio 已经在 Python 中使用很多年了,但它仍然是 Python 中最有趣但也是最令人沮丧的领域之一。
对于新开发人员来说,开始使用 asyncio 非常困难。
本指南对 Python 中的 asyncio 进行了详细而全面的回顾,包括如何定义、创建和运行协程、什么是异步编程、什么是非阻塞 io、与协程一起使用的并发原语、 常见问题和最佳实践。
这是一本超过 29,000 字的海量指南。 您可能需要为其添加书签,以便在开发并发程序时可以参考它。
让我们深入了解一下。
Asyncio allows us to use asynchronous programming with coroutine-based concurrency in Python.
Although asyncio has been available in Python for many years now, it remains one of the most interesting and yet one of the most frustrating areas of Python.
It is just plain hard to get started with asyncio for new developers.
This guide provides a detailed and comprehensive(全面的) review of asyncio in Python, including how to define, create and run coroutines, what is asynchronous programming, what is non-blocking-io, concurrency primitives(原始并发) used with coroutines, common questions, and best practices.
This is a massive 29,000+ word guide. You may want to bookmark it so you can refer to it as you develop your concurrent programs.
Let’s dive in.
创建日期: 2024年9月4日