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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
42
TDD, BDD and Beyond
ipfans
0
51
Go最差实践
ipfans
0
33
Go的版本管理之路
ipfans
0
86
Other Decks in Programming
See All in Programming
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
660
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
200
Apache Iceberg V3 and migration to V3
tomtanaka
0
170
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
480
Gemini for developers
meteatamel
0
100
24時間止められないシステムを守る-医療ITにおけるランサムウェア対策の実際
koukimiura
1
130
dchart: charts from deck markup
ajstarks
3
1k
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
740
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
310
Fluid Templating in TYPO3 14
s2b
0
130
CSC307 Lecture 01
javiergs
PRO
0
690
SourceGeneratorのススメ
htkym
0
200
Featured
See All Featured
Ruling the World: When Life Gets Gamed
codingconduct
0
150
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
66
37k
WCS-LA-2024
lcolladotor
0
450
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
GraphQLの誤解/rethinking-graphql
sonatard
74
11k
Building Adaptive Systems
keathley
44
2.9k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
750
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
Test your architecture with Archunit
thirion
1
2.2k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
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!