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
flask with server-sent events
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
cppgohan
January 13, 2013
Technology
1.9k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
flask with server-sent events
sztechparty
cppgohan
January 13, 2013
More Decks by cppgohan
See All by cppgohan
ReactNative for Android first look
gohan
0
81
Introduction to Bittorrent sync
gohan
0
120
Twitter bootstrap 小试
gohan
0
110
Introduction To Hubot
gohan
1
240
Other Decks in Technology
See All in Technology
【NRUG vol.18】KubernetesにおけるNew Relicデータ取得量削減の考え方
nrug_member
0
160
SONiCの統計情報を取得したい
sonic
0
230
自宅LLMの話
jacopen
1
620
AI時代のコスト管理を考えよう〜明日から使える実践AWSノウハウ~
yoshimi0227
0
270
LayerX コーポレートエンジニアリング室におけるサプライチェーンセキュリティへの取り組み / Supply Chain Security at LayerX Corporate Engineering
yuyatakeyama
2
670
2026TECHFRESH畢業分享會 - Lightning Talk - 資料也要 CI/CD? 用 Airbyte 自動化資料同步
line_developers_tw
PRO
0
1.3k
2026TECHFRESH畢業分享會 - 原生還是跨平台? App 開發踩坑實錄
line_developers_tw
PRO
0
1.3k
入門!AWS Blocks
ysuzuki
1
160
日本 Fintech 未来予測レポート 2027〜2028年(オリジナル版)
8maki
0
2.3k
AIのReact習熟度を測る
uhyo
2
650
Socrates × Looker 〜セマンティックレイヤーで進化するデータ分析エージェント〜
hanon52_
3
2.5k
Agile and AI Redmine Japan 2026
hiranabe
3
190
Featured
See All Featured
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
210
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1.1k
Become a Pro
speakerdeck
PRO
31
6k
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Building Adaptive Systems
keathley
44
3.1k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
860
The Mindset for Success: Future Career Progression
greggifford
PRO
0
360
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
290
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
The Spectacular Lies of Maps
axbom
PRO
1
810
Why Our Code Smells
bkeepers
PRO
340
58k
Transcript
@cppgohan with Server-Sent Events
Flask?
Flask? MicroFramework again...
Flask? MicroFramework again... Written in Python
=
=
Werkzeug WSGI utility library =
+ Werkzeug WSGI utility library =
+ Werkzeug WSGI utility library =
+ Werkzeug WSGI utility library Jinja2 template engine =
Hello.py Demo
Hello.py Demo
Hello.py Demo
index.html Demo
index.html Demo result???
index.html Demo result??? • terminal run: python hello.py • open
http://localhost:5000
Server-Sent Event server push的html5标准, 用法简易, 单次连接比polling高效些. 相比websocket的双向二进制数据, Server-Sent Event只是单向, HTTP协议.
(但浏览器调试工具往往没法看到服务器发来的数据, X_X) Server对Client的请求, 做stream方式的响应.
Server-Sent Event
Server-Sent Event 支 持 率 不 高 , 暂 时
只 能 ”玩 ” 要 兼 容 处 理
Demo index.html
Demo hello.py
Demo redis:
Demo redis: demo:FILE_TEXT -- 每次python读出来的文本 demo:FILE_TEXT_SEQ -- 为文本版本号, 每次文本更新, 版本号+1
/sever_push响应 -- 当FILE_TEXT_SEQ增加时, 将最新的文本返回给浏览器
Demo result???
Demo result??? • terminal run: python hello.py
Demo result??? • terminal run: python hello.py • open http://localhost:5000
Demo result??? • terminal run: python hello.py • open http://localhost:5000
• block!!!
Demo result??? • terminal run: python hello.py • open http://localhost:5000
• block!!! solution???
Demo result??? • terminal run: python hello.py • open http://localhost:5000
• block!!! • async WSGI server! (eg. gunicorn + gevent, gevent) solution???
Demo result??? • terminal run: python hello.py • open http://localhost:5000
• block!!! • async WSGI server! (eg. gunicorn + gevent, gevent) • terminal run: gunicorn -k gevent -b '0.0.0.0:5000' hello:app solution???
Demo result??? • terminal run: python hello.py • open http://localhost:5000
• block!!! • async WSGI server! (eg. gunicorn + gevent, gevent) • terminal run: gunicorn -k gevent -b '0.0.0.0:5000' hello:app • open http://localhost:5000 solution???
Demo result??? • terminal run: python hello.py • open http://localhost:5000
• block!!! • async WSGI server! (eg. gunicorn + gevent, gevent) • terminal run: gunicorn -k gevent -b '0.0.0.0:5000' hello:app • open http://localhost:5000 • open http://localhost:5000 again! solution???
More Demo Server下发代码示例
More Demo • start web server • open http://localhost:5000 •
server push js script... • browser excute js script... • ... Server下发代码示例
More Usage •网站动态更新 •区分客户端推送 •微博墙实现 •webgame服务器推送 •浏览器插件
Resources • http://www.python.org/dev/peps/pep-0333/ • http://werkzeug.pocoo.org/ • http://jinja.pocoo.org/ • http://flask.pocoo.org/ •
http://www.gevent.org/ • http://gunicorn.org/ • http://dev.w3.org/html5/eventsource/ • http://www.html5rocks.com/en/tutorials/eventsource/basics/ • http://www.w3schools.com/html/html5_serversentevents.asp
END; 2013, 分享不止!