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
59
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
Tweet
Share
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
33
TDD, BDD and Beyond
ipfans
0
32
Go最差实践
ipfans
0
31
Go的版本管理之路
ipfans
0
73
Other Decks in Programming
See All in Programming
単体テストの始め方/作り方
toms74209200
0
410
[初登壇@jAZUG]アプリ開発者が気になるGoogleCloud/Azure+wasm/wasi
asaringo
0
120
💎 My RubyKaigi Effect in 2025: Top Ruby Companies 🌐
yasulab
PRO
1
130
F#で自在につくる静的ブログサイト - 関数型まつり2025
pizzacat83
0
280
Cloudflare Realtime と Workers でつくるサーバーレス WebRTC
nekoya3
0
370
〜可視化からアクセス制御まで〜 BigQuery×Looker Studioで コスト管理とデータソース認証制御する方法
cuebic9bic
3
320
Bytecode Manipulation 으로 생산성 높이기
bigstark
1
190
RubyKaigiで得られる10の価値 〜Ruby話を聞くことだけが RubyKaigiじゃない〜
tomohiko9090
0
130
eBPFを用いたAIネットワーク監視システム論文の実装 / eBPF Japan Meetup #4
yuukit
3
740
XSLTで作るBrainfuck処理系
makki_d
0
180
Enterprise Web App. Development (2): Version Control Tool Training Ver. 5.1
knakagawa
1
110
GoのWebAssembly活用パターン紹介
syumai
3
9.5k
Featured
See All Featured
Done Done
chrislema
184
16k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Stop Working from a Prison Cell
hatefulcrawdad
269
20k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Rebuilding a faster, lazier Slack
samanthasiow
81
9k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
228
22k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.7k
Building an army of robots
kneath
306
45k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
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!