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
0
73
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
Tweet
Share
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
43
TDD, BDD and Beyond
ipfans
0
53
Go最差实践
ipfans
0
34
Go的版本管理之路
ipfans
0
87
Other Decks in Programming
See All in Programming
今から始めるClaude Code超入門
448jp
8
9.4k
AIとペアプロして処理時間を97%削減した話 #pyconshizu
kashewnuts
1
120
その「common」ディレクトリ、腐っていませんか?
kinocoboy2
1
110
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
240
CSC307 Lecture 08
javiergs
PRO
0
690
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.9k
Package Management Learnings from Homebrew
mikemcquaid
0
270
SourceGeneratorのススメ
htkym
0
650
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
140
Metaprogramming isn't real, it can't hurt you
okuramasafumi
0
120
ご飯食べながらエージェントが開発できる。そう、Agentic Engineeringならね。
yokomachi
1
240
Premier Disciplin for Micro Frontends Multi Version/ Framework Scenarios @OOP 2026, Munic
manfredsteyer
PRO
0
170
Featured
See All Featured
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.9k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
130
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.1k
Embracing the Ebb and Flow
colly
88
5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
140
Designing Experiences People Love
moore
144
24k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4k
Rails Girls Zürich Keynote
gr2m
96
14k
Facilitating Awesome Meetings
lara
57
6.8k
Unsuck your backbone
ammeep
671
58k
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!