Skip to Content
Python语言及其应用(第2版)
book

Python语言及其应用(第2版)

by Bill Lubanovic
March 2022
Intermediate to advanced content levelIntermediate to advanced
522 pages
13h 52m
Chinese
Posts & Telecom Press
Content preview from Python语言及其应用(第2版)
440
附录
C
t2 = time.time()
print(f"{(t2-t1):.04}\t{len(r.content)}\t{url}")
async def get_sites(sites):
t1 = time.time()
async with trio.open_nursery() as nursery:
for url in sites:
nursery.start_soon(get_one, url, t1)
if __name__ == "__main__":
print("seconds\tbytes\turl")
trio.run(get_sites, urls)
结果如下:
$
python trio_asks_sites.py
seconds bytes url
0.1287 5735 https://exampleurl1
0.2134 146082 https://exampleurl4
0.215 11029 https://exampleurl2
0.3813 52385 https://exampleurl3
注意,
trio
并没有使用
asyncio.run()
,而是使用了自己的
trio.open_nursery()
。如果
感到好奇,可以读读文章“
What is the core dif
ference between asyncio and trio?
”以及关于
trio
设计决策的讨论。
有一个叫作
AnyIO
的新包提供了
asyncio ...
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编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano
Python实用技能学习指南

Python实用技能学习指南

Posts & Telecom Press, Robert Smallshire, Austin Bingham
Python技术基础视频教程

Python技术基础视频教程

保罗·J·戴特尔
Python面向对象编程指南

Python面向对象编程指南

Posts & Telecom Press, Steven F. Lott

Publisher Resources

ISBN: 9787115586223