Skip to Content
流畅的Python(第2版)
book

流畅的Python(第2版)

by Luciano Ramalho
April 2023
Intermediate to advanced
769 pages
25h 16m
Chinese
Posts & Telecom Press
Content preview from 流畅的Python(第2版)
636
21
最后,推荐阅读
Bob Nystrom
写的“
What Color Is Your Function?
”一文。这篇文章讨论了
JavaScript
Python
C#
等语言中常规函数和异步函数
(即协程)不相容的执行模型。内容
剧透:
Nystrom
得出结论
Go
语言的做法是正确的,即所有函数的颜色相同。我喜欢
Go
语言的这种做法。但是,我也觉得
Nathaniel
J. Smith
在“
Go statement considered harmful
一文中所说的有道理。世间不完美,并发编程始终是难题。
杂谈
一个速度慢的函数差点儿毁掉
uvloop
的基准测试
2016
年,
Yury Selivanov
发布了
uvloop
。这是“一个事件循环,可以直接取代
asyncio
内置的事件循环,速度更快”。当年宣布这个库问世的博客文章提供了基准测试,表现
让人赞叹。他写道:“(
uvloop
)至少比
Node.js
gevent
,以及其他
Python
异步框架快
2
倍。基于
uvloop
asyncio
,性能接近
Go
程序。”
然而,那篇文章也指出,若想与
Go
语言的性能相当,需要满足两个条件。
1.
配置
Go
语言使用单个线程。这样
Go
语言运行时的行为才与
asyncio
类似:通过
同一个线程中由一个事件循环驱动的多个协程实现并发。
18
2.
使用
Python 3.5
编写代码,而且除了
uvloop
自身,还要使用
httptools
Selivanov
使用
aiohttp
(早期使用
asyncio
实现的全功能
HTTP
库之一)对
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python高级编程(第2版)

Python高级编程(第2版)

Posts & Telecom Press, Michał Jaworski, Tarek Ziadé
Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty
Python贝叶斯分析(第2版)

Python贝叶斯分析(第2版)

Posts & Telecom Press, Osvaldo Martin

Publisher Resources

ISBN: 9787115612366