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
72
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
Tweet
Share
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
41
TDD, BDD and Beyond
ipfans
0
47
Go最差实践
ipfans
0
33
Go的版本管理之路
ipfans
0
85
Other Decks in Programming
See All in Programming
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.8k
Vibe codingでおすすめの言語と開発手法
uyuki234
0
210
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
1k
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
0
200
GISエンジニアから見たLINKSデータ
nokonoko1203
0
200
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
370
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
490
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
670
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
0
820
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
210
AgentCoreとHuman in the Loop
har1101
5
210
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
170
Featured
See All Featured
Speed Design
sergeychernyshev
33
1.5k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
440
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1.1k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
210
Between Models and Reality
mayunak
1
180
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
46
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Building the Perfect Custom Keyboard
takai
2
680
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
93
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
310
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.9k
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!