官术网_书友最值得收藏!

Summary

Python has had support for asynchronous programming since version 1.5.2, with the introduction of the asyncore and asynchat modules for asynchronous network programming. Version 2.5 introduced the ability to send data to coroutines via yield expressions, allowing us to write asynchronous code in a simpler but more powerful way. Python 3.4 introduced a new library for asynchronous I/O called asyncio.

Python 3.5 introduced true coroutine types via async def and await. Interested readers are encouraged to explore these new developments. One word of warning though: asynchronous programming is a powerful tool that can dramatically improve the performance of I/O-intensive code. It does not come without issues, though, the main of which is complexity.

Any important asynchronous code has to carefully select nonblocking libraries in order to avoid using blocking code. It has to implement a coroutine scheduler (since the OS does not schedule coroutines for us like it does with threads), which involves writing an event loop and adding further complexity. Reading asynchronous code can be challenging to the point that even our simple examples do not look all that simple at first sight. Handle with care!

主站蜘蛛池模板: 哈尔滨市| 泰和县| 建湖县| 清水县| 江孜县| 西昌市| 思茅市| 宜章县| 保亭| 玛沁县| 柳江县| 广平县| 师宗县| 阿鲁科尔沁旗| 赤城县| 丽江市| 抚顺县| 洪江市| 白沙| 辽宁省| 利津县| 仲巴县| 巩留县| 容城县| 长丰县| 永州市| 汉川市| 南部县| 昌黎县| 海安县| 泰宁县| 舒城县| 武城县| 封丘县| 兰州市| 荣昌县| 霍邱县| 闵行区| 县级市| 东乡| 孟连|