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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
ipfans
November 25, 2018
Programming
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
68
TDD, BDD and Beyond
ipfans
0
100
Go最差实践
ipfans
0
59
Go的版本管理之路
ipfans
0
140
Other Decks in Programming
See All in Programming
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
620
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
34
15k
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
580
setup-vp GitLab対応の裏側
naokihaba
0
150
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
340
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
130
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
13
6.5k
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
440
mrbgem 三角測量 開発
ogom
0
200
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5.4k
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
310
Heart of Swift Concurrency
koher
0
1.2k
Featured
See All Featured
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
910
Utilizing Notion as your number one productivity tool
mfonobong
4
610
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Ethics towards AI in product and experience design
skipperchong
2
410
Fireside Chat
paigeccino
43
4k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
New Earth Scene 8
popppiees
4
2.6k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
58k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
How to build a perfect <img>
jonoalderson
1
6.1k
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!