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
68
现代方式使用asyncio
使用Python asyncio的一些姿势
ipfans
November 25, 2018
Tweet
Share
More Decks by ipfans
See All by ipfans
Event Modeling: 新项目沟通方式
ipfans
0
39
TDD, BDD and Beyond
ipfans
0
41
Go最差实践
ipfans
0
33
Go的版本管理之路
ipfans
0
83
Other Decks in Programming
See All in Programming
Atomics APIを知る / Understanding Atomics API
ssssota
1
200
AI時代もSEOを頑張っている話
shirahama_x
0
160
Agentに至る道 〜なぜLLMは自動でコードを書けるようになったのか〜
mackee
5
1.9k
高単価案件で働くための心構え
nullnull
0
160
予防に勝る防御なし(2025年版) - 堅牢なコードを導く様々な設計のヒント / Growing Reliable Code PHP Conference Fukuoka 2025
twada
PRO
39
13k
なぜ強調表示できず ** が表示されるのか — Perlで始まったMarkdownの歴史と日本語文書における課題
kwahiro
12
7.2k
AI 時代だからこそ抑えたい「価値のある」PHP ユニットテストを書く技術 #phpconfuk / phpcon-fukuoka-2025
shogogg
1
580
全員アーキテクトで挑む、 巨大で高密度なドメインの紐解き方
agatan
7
8.9k
スタートアップを支える技術戦略と組織づくり
pospome
8
11k
関数の挙動書き換える
takatofukui
4
750
OSS開発者の憂鬱
yusukebe
12
5.9k
最新のDirectX12で使えるレイトレ周りの機能追加について
projectasura
0
300
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
37
3.5k
Raft: Consensus for Rubyists
vanstee
140
7.2k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
Agile that works and the tools we love
rasmusluckow
331
21k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
The Cost Of JavaScript in 2023
addyosmani
55
9.3k
Automating Front-end Workflow
addyosmani
1371
200k
Scaling GitHub
holman
464
140k
The Cult of Friendly URLs
andyhume
79
6.7k
Done Done
chrislema
186
16k
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!