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
66
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
Tweet
Share
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
39
TDD, BDD and Beyond
ipfans
0
39
Go最差实践
ipfans
0
32
Go的版本管理之路
ipfans
0
82
Other Decks in Programming
See All in Programming
CSC305 Lecture 02
javiergs
PRO
1
260
Pull-Requestの内容を1クリックで動作確認可能にするワークフロー
natmark
1
380
2025年版 サーバーレス Web アプリケーションの作り方
hayatow
23
25k
Local Peer-to-Peer APIはどのように使われていくのか?
hal_spidernight
2
430
defer f()とdefer fの挙動を 誤解していた話
kogamochiduki
2
160
なぜGoのジェネリクスはこの形なのか? Featherweight Goが明かす設計の核心
ryotaros
7
1k
CI_CD「健康診断」のススメ。現場でのボトルネック特定から、健康診断を通じた組織的な改善手法
teamlab
PRO
0
150
Web フロントエンドエンジニアに開かれる AI Agent プロダクト開発 - Vercel AI SDK を観察して AI Agent と仲良くなろう! #FEC余熱NIGHT
izumin5210
2
300
CSC509 Lecture 02
javiergs
PRO
0
400
After go func(): Goroutines Through a Beginner’s Eye
97vaibhav
0
210
なぜあの開発者はDevRelに伴走し続けるのか / Why Does That Developer Keep Running Alongside DevRel?
nrslib
1
310
ててべんす独演会〜Flowの全てを語ります〜
tbsten
1
220
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Faster Mobile Websites
deanohume
310
31k
The Straight Up "How To Draw Better" Workshop
denniskardys
237
140k
Git: the NoSQL Database
bkeepers
PRO
431
66k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
GraphQLとの向き合い方2022年版
quramy
49
14k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.5k
Producing Creativity
orderedlist
PRO
347
40k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.1k
The Language of Interfaces
destraynor
162
25k
Java REST API Framework Comparison - PWX 2021
mraible
33
8.8k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6.1k
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!