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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
ipfans
November 25, 2018
Programming
0
75
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
Tweet
Share
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
45
TDD, BDD and Beyond
ipfans
0
58
Go最差实践
ipfans
0
36
Go的版本管理之路
ipfans
0
90
Other Decks in Programming
See All in Programming
20260315 AWSなんもわからん🥲
chiilog
2
150
技術検証結果の整理と解析をAIに任せよう!
keisukeikeda
0
120
Codex の「自走力」を高める
yorifuji
0
1.2k
Codexに役割を持たせる 他のAIエージェントと組み合わせる実務Tips
o8n
4
1.3k
maplibre-gl-layers - 地図に移動体たくさん表示したい
kekyo
PRO
0
260
エラーログのマスキングの仕組みづくりに役立ったASTの話
kumoichi
0
210
20260313 - Grafana & Friends Taipei #1 - Kubernetes v1.36 的開發雜記:那些困在 Alpha 加護病房太久的 Metrics
tico88612
0
180
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
500
RAGでハマりがちな"Excelの罠"を、データの構造化で突破する
harumiweb
9
2.8k
ロボットのための工場に灯りは要らない
watany
10
2.8k
AI 開発合宿を通して得た学び
niftycorp
PRO
0
100
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
140
Featured
See All Featured
AI: The stuff that nobody shows you
jnunemaker
PRO
3
380
Odyssey Design
rkendrick25
PRO
2
540
How STYLIGHT went responsive
nonsquared
100
6k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
310
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
150
WENDY [Excerpt]
tessaabrams
9
36k
Ruling the World: When Life Gets Gamed
codingconduct
0
170
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
83
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
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!