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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
ipfans
November 25, 2018
Programming
83
0
Share
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
50
TDD, BDD and Beyond
ipfans
0
68
Go最差实践
ipfans
0
46
Go的版本管理之路
ipfans
0
98
Other Decks in Programming
See All in Programming
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
250
UaaL×Androidアプリのメモリ計測 — Memory Profilerの先へ
rio432
0
130
Terraform言語の静的解析 / static analysis of Terraform language
wata727
1
140
書き換えて学ぶTemporal #fukts
pirosikick
2
360
Explore CoroutineScope
tomoeng11
0
170
SREに優しいTerraform構成 modulesとstateの組み方
hiyanger
2
170
いつか誰かが、と思っていた フロントエンド刷新5年間の実践知
kiichisugihara
1
260
How We Practice Exploratory Testing in Iterative Development( #scrumniigata ) / 反復開発の中で、探索的テストをどう実施しているか
teyamagu
PRO
3
740
Are We Really Coding 10× Faster with AI?
kohzas
0
130
実践ハーネスエンジニアリング:ステアリングループを実例から読み解く / Practical Harness Engineering: Understanding Steering Loops Through Real-World Examples
nrslib
5
4.5k
〜バイブコーディングを超えて〜 チームで実験し続けたAI駆動開発
tigertora7571
0
190
AIを導入する前にやるべきこと
negima
2
340
Featured
See All Featured
KATA
mclloyd
PRO
35
15k
The untapped power of vector embeddings
frankvandijk
2
1.7k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.6k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
110
Embracing the Ebb and Flow
colly
88
5k
The Curse of the Amulet
leimatthew05
1
12k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
500
The Cult of Friendly URLs
andyhume
79
6.9k
Accessibility Awareness
sabderemane
1
110
30 Presentation Tips
portentint
PRO
1
290
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!