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
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
680
10 Tips of AWS ~Gen AI on AWS~
licux
5
390
The Monolith Strikes Back: Why AI Agents ❤️ Rails Monoliths
serradura
0
330
PHP で mp3 プレイヤーを実装しよう
m3m0r7
PRO
0
270
ドメインイベントでビジネスロジックを解きほぐす #phpcon_odawara
kajitack
3
770
Xdebug と IDE による デバッグ実行の仕組みを見る / Exploring-How-Debugging-Works-with-Xdebug-and-an-IDE
shin1x1
0
380
2026-03-27 #terminalnight 変数展開とコマンド展開でターミナル作業をスマートにする方法
masasuzu
0
330
瑠璃の宝石に学ぶ技術の声の聴き方 / 【劇場版】アニメから得た学びを発表会2026 #エンジニアニメ
mazrean
0
250
事業会社でのセキュリティ長期インターンについて
masachikaura
0
250
[RubyKaigi 2026] Require Hooks
palkan
0
170
UIの境界線をデザインする | React Tokyo #15 メイントーク
sasagar
2
360
Offline should be the norm: building local-first apps with CRDTs & Kotlin Multiplatform
renaudmathieu
0
210
Featured
See All Featured
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
680
Abbi's Birthday
coloredviolet
2
7.1k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
330
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
200
Site-Speed That Sticks
csswizardry
13
1.2k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.4k
Color Theory Basics | Prateek | Gurzu
gurzu
0
290
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
sira's awesome portfolio website redesign presentation
elsirapls
0
220
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
200
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.2k
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!