Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
现代方式使用asyncio
Search
ipfans
November 25, 2018
Programming
110
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
66
TDD, BDD and Beyond
ipfans
0
93
Go最差实践
ipfans
0
57
Go的版本管理之路
ipfans
0
130
Other Decks in Programming
See All in Programming
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
560
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
3
550
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
140
アクセシビリティから考える情報設計
high_g_engineer
0
370
FreeBSDでZabbixを動かす.pdf
kenkino
0
270
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
1
310
AIは賢い。でも実行環境は? CLIおじさんがAI時代に伝えたいこと ~ CLIおじさんがAI時代に伝えたいこと ~
curekoshimizu
1
240
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
250
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
110
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
250
What We Talk About When We Talk About XP
m_seki
2
620
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
120
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
187
23k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.1k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
240
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
410
Prompt Engineering for Job Search
mfonobong
0
450
sira's awesome portfolio website redesign presentation
elsirapls
0
410
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1k
The SEO identity crisis: Don't let AI make you average
varn
0
560
A designer walks into a library…
pauljervisheath
211
25k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.6k
How to build a perfect <img>
jonoalderson
1
6k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
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!