Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
现代方式使用asyncio
Search
ipfans
November 25, 2018
Programming
150
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
Transcript
33 slides
现代⽅方式使⽤用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!
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
76
TDD, BDD and Beyond
ipfans
0
120
Go最差实践
ipfans
0
65
Go的版本管理之路
ipfans
0
150
Other Decks in Programming
See All in Programming
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
690
Ruby から Emacs を操作したい
phigasui
0
340
プロジェクトコードをキレイキレイしよう!暗黙的な参照を読み解く静的解析
ostk0069
0
220
protojson における文字化けの扱い
kazuki1023
0
440
ローカルLLMの基本と近況 2611 / Local LLM basics and recent situation 2611
kishida
3
580
Claude Codeのおかげでやりたいことがやれるようになったんだよォー!
sms_tech
0
140
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
140
AI-Powered Domain-Driven Design
ziobrando
0
470
ビジネスロジックを堅牢に~Scala 3のドメインプリミティブ~
j5ik2o
0
200
[Kotlin Fest 2026] eBPF Tracing for Kotlin
takehaya
1
330
Distance field of Julia set
kinakomoti321
0
330
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
590
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
42
3.2k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
770
From π to Pie charts
rasagy
1
450
HDC tutorial
michielstock
2
1k
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
480
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
850
Site-Speed That Sticks
csswizardry
13
1.6k
Prompt Engineering for Job Search
mfonobong
0
590
How GitHub (no longer) Works
holman
316
150k