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
73
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
Tweet
Share
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
43
TDD, BDD and Beyond
ipfans
0
52
Go最差实践
ipfans
0
34
Go的版本管理之路
ipfans
0
87
Other Decks in Programming
See All in Programming
DSPy入門 Pythonで実現する自動プロンプト最適化 〜人手によるプロンプト調整からの卒業〜
seaturt1e
1
180
Claude Code、ちょっとした工夫で開発体験が変わる
tigertora7571
0
150
2026/02/04 AIキャラクター人格の実装論 口 調の模倣から、コンテキスト制御による 『思想』と『行動』の創発へ
sr2mg4
0
570
浮動小数の比較について
kishikawakatsumi
0
320
AIに仕事を丸投げしたら、本当に楽になれるのか
dip_tech
PRO
0
150
個人開発は儲からない - それでも開発開始1ヶ月で300万円売り上げた方法
taishiyade
0
110
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
420
文字コードの話
qnighy
36
14k
ぼくの開発環境2026
yuzneri
1
280
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
390
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
2
690
Rubyと楽しいをつくる / Creating joy with Ruby
chobishiba
0
180
Featured
See All Featured
SEO for Brand Visibility & Recognition
aleyda
0
4.3k
Six Lessons from altMBA
skipperchong
29
4.2k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
The Curse of the Amulet
leimatthew05
1
9k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
130
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
How to make the Groovebox
asonas
2
2k
Statistics for Hackers
jakevdp
799
230k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
330
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
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!