Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
现代方式使用asyncio
Search
ipfans
November 25, 2018
Programming
0
70
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
Tweet
Share
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
39
TDD, BDD and Beyond
ipfans
0
45
Go最差实践
ipfans
0
33
Go的版本管理之路
ipfans
0
83
Other Decks in Programming
See All in Programming
AIエンジニアリングのご紹介 / Introduction to AI Engineering
rkaga
8
2.8k
tparseでgo testの出力を見やすくする
utgwkk
2
230
AWS CDKの推しポイントN選
akihisaikeda
1
240
生成AIを利用するだけでなく、投資できる組織へ
pospome
2
340
複数人でのCLI/Infrastructure as Codeの暮らしを良くする
shmokmt
5
2.3k
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
390
まだ間に合う!Claude Code元年をふりかえる
nogu66
5
840
これならできる!個人開発のすゝめ
tinykitten
PRO
0
110
AIコーディングエージェント(Gemini)
kondai24
0
230
Giselleで作るAI QAアシスタント 〜 Pull Requestレビューに継続的QAを
codenote
0
190
Cap'n Webについて
yusukebe
0
130
TUIライブラリつくってみた / i-just-make-TUI-library
kazto
1
390
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Producing Creativity
orderedlist
PRO
348
40k
4 Signs Your Business is Dying
shpigford
186
22k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Done Done
chrislema
186
16k
Writing Fast Ruby
sferik
630
62k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Agile that works and the tools we love
rasmusluckow
331
21k
Making Projects Easy
brettharned
120
6.5k
Building Applications with DynamoDB
mza
96
6.8k
A Modern Web Designer's Workflow
chriscoyier
698
190k
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!