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
76
0
Share
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
47
TDD, BDD and Beyond
ipfans
0
60
Go最差实践
ipfans
0
37
Go的版本管理之路
ipfans
0
93
Other Decks in Programming
See All in Programming
メッセージングを利用して時間的結合を分離しよう #phperkaigi
kajitack
3
520
Kubernetesでセルフホストが簡単なNewSQLを求めて / Seeking a NewSQL Database That's Simple to Self-Host on Kubernetes
nnaka2992
0
190
The free-lunch guide to idea circularity
hollycummins
0
390
Mastering Event Sourcing: Your Parents Holidayed in Yugoslavia
super_marek
0
130
20260313 - Grafana & Friends Taipei #1 - Kubernetes v1.36 的開發雜記:那些困在 Alpha 加護病房太久的 Metrics
tico88612
0
240
Reactive ❤️ Loom: A Forbidden Love Story
franz1981
2
210
RailsのValidatesをSwift Macrosで再現してみた
hokuron
0
140
安いハードウェアでVulkan
fadis
1
850
Claude Code Skill入門
mayahoney
0
450
ポーリング処理廃止によるイベント駆動アーキテクチャへの移行
seitarof
3
1.3k
夢の無限スパゲッティ製造機 -実装篇- #phpstudy
o0h
PRO
0
180
20260320登壇資料
pharct
0
140
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
94
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
120
How to Think Like a Performance Engineer
csswizardry
28
2.5k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.7k
Bash Introduction
62gerente
615
210k
The SEO identity crisis: Don't let AI make you average
varn
0
430
Navigating Weather and Climate Data
rabernat
0
150
Information Architects: The Missing Link in Design Systems
soysaucechin
0
850
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
160
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
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!