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
Concurrency to Channels
Search
Andrew Godwin
October 08, 2017
Programming
360
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Concurrency to Channels
My keynote from Python Brasil 13 (2017).
Andrew Godwin
October 08, 2017
More Decks by Andrew Godwin
See All by Andrew Godwin
Reconciling Everything
andrewgodwin
1
400
Django Through The Years
andrewgodwin
0
330
Writing Maintainable Software At Scale
andrewgodwin
0
530
A Newcomer's Guide To Airflow's Architecture
andrewgodwin
0
430
Async, Python, and the Future
andrewgodwin
2
750
How To Break Django: With Async
andrewgodwin
1
830
Taking Django's ORM Async
andrewgodwin
0
850
The Long Road To Asynchrony
andrewgodwin
0
770
The Scientist & The Engineer
andrewgodwin
1
860
Other Decks in Programming
See All in Programming
React本体のコードリーディング
high_g_engineer
1
140
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
550
170k Jobs a Day on GKE: Scaling Mercari's CI Platform - and What's Next for AI-Native Development
junyaokabe
0
110
AI Readyの正体はデータマネジメントだ メダリオン2.0の最前線
freee
PRO
0
240
Built Our Own Background Agent at LayerX
layerx
PRO
10
5.5k
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
210
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
リアルな遅延を測る仕様
kota_yata
1
100
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
330
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
4.4k
Google Apps Script で Ruby を動かす
kawahara
0
230
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
180
Featured
See All Featured
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
410
Design in an AI World
tapps
1
280
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
Code Reviewing Like a Champion
maltzj
528
40k
The Cost Of JavaScript in 2023
addyosmani
55
10k
My Coaching Mixtape
mlcsv
0
230
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
540
Site-Speed That Sticks
csswizardry
13
1.4k
Designing Experiences People Love
moore
143
24k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Transcript
Andrew Godwin @andrewgodwin
Hi, I’m Andrew Godwin • Django core developer • Senior
Software Engineer at • South, Django migrations, Channels
What is Channels?
What is Channels?
Why Channels?
2000 2008 2015
Python 1.5 Threading 2000
Twisted 1.0 2002
WSGI (PEP 333) 2003
Python 2.6 Multiprocessing 2008
Django 1.0 2008
Eventlet / gevent 2009
Python 3.4 asyncio 2014
Python 3.5 async / await 2015
Web request handling is “solved” We have good patterns and
standards
Web request handling is easy It’s stateless, and has a
fixed response pattern
Client Server Request Response Process
Other protocols are not so easy Like WebSockets and MQTT
This is why they are more efficient No overheads of
cookies, headers and TCP handshake
Client Server Connect Data ??? Data Data Data
Writing async code is harder There’s a reason we don’t
do it all the time
Deadlocks Livelocks Race conditions Resource starvation
Simple Race Condition
Thread 1 Thread 2 if self.funds[..] < .. if self.funds[..]
< .. self.funds[..] += .. self.funds[..] -= .. self.funds[..] += .. self.funds[..] -= .. {"a": 20, "b": 0} {"a": 0, "b": 20} {"a": -20, "b": 40}
“Fixing” it, but actually adding a deadlock
Thread 1 Thread 2 get lock a get lock b
release lock b release lock a get lock b get lock a release lock a release lock b
Thread 1 Thread 2 get lock a get lock b
get lock b get lock a
More threads = more problems And hard to find in
development when you have no users
CSP “Communicating Sequential Processes” Algebra for talking about concurrency &
problems
You don’t need everything async Only the important bits
Channels: sync + async tooling Traditional synchronous Django with async
handling
“ASGI”: WSGI + async An interface that works for more
than request-response.
Goal: You mostly write sync code Channels/Django handles the annoying
part
Sync code for async behaviour
Why not just use asyncio? Do we need channels at
all?
Channels 1: Can’t write async code too Have to write
it separate outside of Channels framework
Channels 2: asyncio + sync support You can write code
as complex as you need to
Channels does not solve everything Neither does Django, the goal
is a good place to start
Working on more than just WebSocket Ways to write Django/Python
against anything with “events”
WebSockets? Emails? Chat? SMS?
What is Django in future? Is it HTTP requests forever?
Making async code easier = good Give people a way
to learn safely
Make Python the best place for these Even if it
doesn’t end up being Django.
Thanks. Andrew Godwin @andrewgodwin aeracode.org