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
68
现代方式使用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
41
Go最差实践
ipfans
0
33
Go的版本管理之路
ipfans
0
83
Other Decks in Programming
See All in Programming
モビリティSaaSにおけるデータ利活用の発展
nealle
0
590
例外処理を理解して、設計段階からエラーを見つけやすく、起こりにくく #phpconfuk
kajitack
12
6.4k
開発生産性が組織文化になるまでの軌跡
tonegawa07
0
190
しっかり学ぶ java.lang.*
nagise
1
410
手軽に積ん読を増やすには?/読みたい本と付き合うには?
o0h
PRO
1
110
DartASTとその活用
sotaatos
2
150
複数チーム並行開発下でのコード移行アプローチ ~手動 Codemod から「生成AI 活用」への進化
andpad
0
180
Claude Code on the Web を超える!? Codex Cloud の実践テク5選
sunagaku
0
600
レイトレZ世代に捧ぐ、今からレイトレを始めるための小径
ichi_raven
0
460
How Software Deployment tools have changed in the past 20 years
geshan
0
4.7k
Promise.tryで実現する新しいエラーハンドリング New error handling with Promise try
bicstone
3
1.5k
関数の挙動書き換える
takatofukui
4
750
Featured
See All Featured
Done Done
chrislema
186
16k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
[RailsConf 2023] Rails as a piece of cake
palkan
57
6.1k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Mobile First: as difficult as doing things right
swwweet
225
10k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
Balancing Empowerment & Direction
lara
5
760
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.3k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Producing Creativity
orderedlist
PRO
348
40k
Code Review Best Practice
trishagee
72
19k
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!