Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
现代方式使用asyncio
Search
ipfans
November 25, 2018
Programming
0
64
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
Tweet
Share
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
38
TDD, BDD and Beyond
ipfans
0
34
Go最差实践
ipfans
0
31
Go的版本管理之路
ipfans
0
80
Other Decks in Programming
See All in Programming
AIエージェント開発、DevOps and LLMOps
ymd65536
1
370
Claude Codeで実装以外の開発フロー、どこまで自動化できるか?失敗と成功
ndadayo
3
1.8k
Jakarta EE Core Profile and Helidon - Speed, Simplicity, and AI Integration
ivargrimstad
0
280
Zendeskのチケットを Amazon Bedrockで 解析した
ryokosuge
3
230
サイトを作ったらNFCタグキーホルダーを爆速で作れ!
yuukis
0
740
Honoアップデート 2025年夏
yusukebe
1
890
Azure SRE Agentで運用は楽になるのか?
kkamegawa
0
900
RDoc meets YARD
okuramasafumi
4
160
TROCCO×dbtで実現する人にもAIにもやさしいデータ基盤
nealle
0
390
Processing Gem ベースの、2D レトロゲームエンジンの開発
tokujiros
2
120
個人軟體時代
ethanhuang13
0
280
MCPとデザインシステムに立脚したデザインと実装の融合
yukukotani
1
850
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
42
2.8k
Into the Great Unknown - MozCon
thekraken
40
2k
[RailsConf 2023] Rails as a piece of cake
palkan
56
5.8k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
570
Site-Speed That Sticks
csswizardry
10
800
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
11
1.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Balancing Empowerment & Direction
lara
3
600
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
61k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
185
54k
Transcript
现代⽅方式使⽤用asyncio Kevin
None
asyncio • 为什什么我们需要异步? • 为什什么选择asyncio? • 如何优雅的编写asyncio程序? • asyncio的其他
asyncio • 为什什么我们需要异步? • 为什什么选择asyncio? • 如何优雅的编写asyncio程序? • asyncio的其他
asyncio • 为什什么我们需要异步? • 为什什么选择asyncio? • 如何优雅的编写asyncio程序? • asyncio的其他
gevent/eventlet
gevent/eventlet
相⽐比gevent • 官⽅方⽀支持,未来的⽅方向 • 显式切换 • 显式处理理条件竞争问题更更容易易 • 显式控制上下⽂文切换,不不再踩坑 •
更更容易易兼容
asyncio • 为什什么我们需要异步? • 为什什么选择asyncio? • 如何优雅的编写asyncio程序? • asyncio的其他
举个例例⼦子
举个例例⼦子
举个例例⼦子
run&serve_forever
asyncio API
asyncio API • 优先使⽤用⾼高级API,提供更更简单的使⽤用⽅方法 • 只有在需要时,才选择使⽤用底层API
再举个例例⼦子
gather
contextvar
contextvar
async传染
async传染
async传染
async传染
Django Channels
flask
responder
asyncio调试 https://docs.python.org/3/library/asyncio-dev.html#debug-mode
aiomonitor
aiomonitor
asyncio • 为什什么我们需要异步? • 为什什么选择asyncio? • 如何优雅的编写asyncio程序? • asyncio的其他
其他:优化 • uvloop • 新版本也是⼀一种优化:
其他:注意事项 • 单独使⽤用asyncio仍旧是单线程模型 • 只有IO才可以并发 • asyncio会带来CPU压⼒力力 • event loop和上下⽂文切换在⾼高并发场景下仍旧有明显消耗
Thank You!