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版)
572
20
并发执行器
抨击线程的往往是系统开发者,他们考虑的使用场景对一般的应用程序开发者来
说,也许一生都不会遇到。……应用程序开发者遇到的使用场景,
99%
的情况下
只需知道如何派生一堆独立的线程,然后用队列收集结果。
——
Michele Simionato
深度思考
Python
的人
1
本章主要讨论实现了
concurrent.futures.Executor
接口的类。这些类对
Michele Simionato
所说的“派生一堆独立线程,通过队列收集结果”的模式进行了封装,使用起来特别容
易,不仅能用于线程,而且还能用于进程处理计算密集型任务。
本章还会介绍“
future
”这一
概念。这种对象表示异步执行的操作,类似于
JavaScript
中的
promise
。这个概念的作用很大
,是
concurrent.futures
模块和
asyncio
包(将在第
21
讨论)的基础。
20.1
 本章新增内容
本章原来的标题是“使用
future
处理并发”,现在改成了“并发执行器”,因为本章主要讨
论执行器这个重要的高级功能。
future
是底层对象
,主要在
20.2.3
节探讨,本章余下内容
不再涉及。
现在,
HTTP
客户端示例全都换用了新的
HTTPX
库。这个库同时提供了同步和异步
API
1
摘自
Michele Simionato
发表的文章“
Threads, processes and concurrency in Python: some thoughts
”,
副标题为“
Removing the hype around ...
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