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
57
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
Tweet
Share
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
32
TDD, BDD and Beyond
ipfans
0
31
Go最差实践
ipfans
0
31
Go的版本管理之路
ipfans
0
72
Other Decks in Programming
See All in Programming
Django for Data Science (Boston Python Meetup, March 2025)
wsvincent
0
320
「影響が少ない」を自分の目でみてみる
o0h
PRO
2
970
State of Namespace
tagomoris
4
720
remix + cloudflare workers (DO) docker上でいい感じに開発する
yoshidatomoaki
0
130
Preact、HooksとSignalsの両立 / Preact: Harmonizing Hooks and Signals
ssssota
1
1.4k
Boost Your Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
1.2k
サービスクラスのありがたみを発見したときの思い出 #phpcon_odawara
77web
4
630
Day0 初心者向けワークショップ実践!ソフトウェアテストの第一歩
satohiroyuki
0
830
コンテナでLambdaをデプロイするときに知っておきたかったこと
_takahash
0
180
フロントエンドテストの育て方
quramy
11
2.9k
Do Dumb Things
mitsuhiko
0
420
リストビュー画面UX改善の振り返り
splcywolf
0
130
Featured
See All Featured
Being A Developer After 40
akosma
91
590k
Why Our Code Smells
bkeepers
PRO
336
57k
Embracing the Ebb and Flow
colly
85
4.6k
Code Review Best Practice
trishagee
67
18k
Testing 201, or: Great Expectations
jmmastey
42
7.4k
Speed Design
sergeychernyshev
29
880
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
34
2.2k
Rails Girls Zürich Keynote
gr2m
94
13k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Scaling GitHub
holman
459
140k
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!