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
72
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
Tweet
Share
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
41
TDD, BDD and Beyond
ipfans
0
47
Go最差实践
ipfans
0
33
Go的版本管理之路
ipfans
0
85
Other Decks in Programming
See All in Programming
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.4k
AgentCoreとHuman in the Loop
har1101
5
210
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
640
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
5.9k
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
ELYZA_Findy AI Engineering Summit登壇資料_AIコーディング時代に「ちゃんと」やること_toB LLMプロダクト開発舞台裏_20251216
elyza
2
1.4k
Architectural Extensions
denyspoltorak
0
260
Fluid Templating in TYPO3 14
s2b
0
120
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
170
dchart: charts from deck markup
ajstarks
3
990
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
110
Denoのセキュリティに関する仕組みの紹介 (toranoana.deno #23)
uki00a
0
280
Featured
See All Featured
So, you think you're a good person
axbom
PRO
2
1.9k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
110
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
110
GitHub's CSS Performance
jonrohan
1032
470k
The agentic SEO stack - context over prompts
schlessera
0
610
We Have a Design System, Now What?
morganepeng
54
8k
ラッコキーワード サービス紹介資料
rakko
1
2.2M
Odyssey Design
rkendrick25
PRO
1
480
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
290
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.7k
Fireside Chat
paigeccino
41
3.8k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
160
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!