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
98
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
60
TDD, BDD and Beyond
ipfans
0
78
Go最差实践
ipfans
0
56
Go的版本管理之路
ipfans
0
110
Other Decks in Programming
See All in Programming
どこまでゆるくて許されるのか
tk3fftk
0
470
関数型プログラミングのメリットって何だろう?
wanko_it
0
160
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
300
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
250
1B+ /day規模のログを管理する技術
broadleaf
0
130
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
240
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
250
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
170
自作OSでスライド発表する
uyuki234
1
3.8k
Creating Composable Callables in Contemporary C++
rollbear
0
200
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
210
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
Featured
See All Featured
Faster Mobile Websites
deanohume
310
32k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
610
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
BBQ
matthewcrist
89
10k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
630
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
310
Claude Code のすすめ
schroneko
67
230k
How to train your dragon (web standard)
notwaldorf
97
6.7k
Marketing to machines
jonoalderson
1
5.6k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
300
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!