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
76
0
Share
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
47
TDD, BDD and Beyond
ipfans
0
60
Go最差实践
ipfans
0
37
Go的版本管理之路
ipfans
0
93
Other Decks in Programming
See All in Programming
Codex の「自走力」を高める
yorifuji
0
1.3k
Feature Toggle は捨てやすく使おう
gennei
0
390
Understanding Apache Lucene - More than just full-text search
spinscale
0
150
今年もTECHSCOREブログを書き続けます!
hiraoku101
0
210
Fundamentals of Software Engineering In the Age of AI
therealdanvega
2
310
実践ハーネスエンジニアリング #MOSHTech
kajitack
7
5.2k
CS教育のDX AIによる育成の効率化
niftycorp
PRO
0
170
Symfony + NelmioApiDocBundle を使った スキーマ駆動開発 / Schema Driven Development with NelmioApiDocBundle
okashoi
0
250
Linux Kernelの1文字のミスで 権限昇格ができた話
rqda
0
2.2k
年間50登壇、単著出版、雑誌寄稿、Podcast出演、YouTube、CM、カンファレンス主催……全部やってみたので面白さ等を比較してみよう / I’ve tried them all, so let’s compare how interesting they are.
nrslib
4
560
AI 開発合宿を通して得た学び
niftycorp
PRO
0
180
Rethinking API Platform Filters
vinceamstoutz
0
4.3k
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
330
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
KATA
mclloyd
PRO
35
15k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
320
Into the Great Unknown - MozCon
thekraken
40
2.3k
Leo the Paperboy
mayatellez
5
1.6k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
AI: The stuff that nobody shows you
jnunemaker
PRO
4
500
First, design no harm
axbom
PRO
2
1.2k
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!