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
76
0
Share
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
49
TDD, BDD and Beyond
ipfans
0
62
Go最差实践
ipfans
0
39
Go的版本管理之路
ipfans
0
94
Other Decks in Programming
See All in Programming
Exploring RuboCop with MCP
koic
0
690
Server-Side Kotlin LT大会 vol.18 [Kotlin-lspの最新情報と Neovimのlsp設定例]
yasunori0418
1
140
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
3
280
年間50登壇、単著出版、雑誌寄稿、Podcast出演、YouTube、CM、カンファレンス主催……全部やってみたので面白さ等を比較してみよう / I’ve tried them all, so let’s compare how interesting they are.
nrslib
4
780
実用!Hono RPC2026
yodaka
2
200
SkillがSkillを生む:QA観点出しを自動化した
sontixyou
6
3.4k
t *testing.T は どこからやってくるの?
otakakot
1
540
10 Tips of AWS ~Gen AI on AWS~
licux
5
390
AWS re:Invent 2025の少し振り返り + DevOps AgentとBacklogを連携させてみた
satoshi256kbyte
3
160
Xdebug と IDE による デバッグ実行の仕組みを見る / Exploring-How-Debugging-Works-with-Xdebug-and-an-IDE
shin1x1
0
380
事業会社でのセキュリティ長期インターンについて
masachikaura
0
250
Google Nest CamとApple Vision frameworkと猫🐈🐈⬛ / onishi50
yutailang0119
0
110
Featured
See All Featured
Thoughts on Productivity
jonyablonski
76
5.1k
Music & Morning Musume
bryan
47
7.2k
Between Models and Reality
mayunak
3
260
Designing Powerful Visuals for Engaging Learning
tmiket
1
340
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
98
[SF Ruby Conf 2025] Rails X
palkan
2
960
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
10k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Scaling GitHub
holman
464
140k
The browser strikes back
jonoalderson
0
970
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!