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 in Python
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Farzad Ghanei
March 15, 2014
Programming
10k
2
Share
Concurrency in Python
Mini PyCon MY 2014
March 2014, Kuala Lumpur
Farzad Ghanei
March 15, 2014
More Decks by Farzad Ghanei
See All by Farzad Ghanei
PHP Testing and Mocking
farzadghanei
0
130
PHP memory management and garbage collection
farzadghanei
1
300
Some of the ways of gathering information
farzadghanei
0
220
Statsd
farzadghanei
0
120
Introduction to StatsD
farzadghanei
0
230
Other Decks in Programming
See All in Programming
Oxlintはいかにしてtsgolintのlint ruleを呼び出しているのか
syumai
2
990
RTSPクライアントを自作してみた話
simotin13
0
310
Hive Metastoreを通して学ぶIceberg REST Catalog ― 仕様から実装まで
okumin
0
300
要はバランスからの卒業 #yumemi_grow
kajitack
0
200
Moments When Things Go Wrong
aurimas
3
120
iOS26時代の新規アプリ開発
yuukiw00w
0
210
JavaDoc 再入門
nagise
0
190
Inside Stream API
skrb
1
250
tsserverとは何だったのか、これからどうなるのか
nowaki28
1
410
サーバーレスで作る、動画データ管理基盤
oyasumipants
0
310
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
130
横断組織出身のQAEがインプロセスQAEでつまずいたこと・活かせたこと
ty89
0
450
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.4k
How STYLIGHT went responsive
nonsquared
100
6.1k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
590
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
It's Worth the Effort
3n
188
29k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Six Lessons from altMBA
skipperchong
29
4.3k
WCS-LA-2024
lcolladotor
0
610
How to make the Groovebox
asonas
2
2.2k
A better future with KSS
kneath
240
18k
Transcript
Concurrency In Python Farzad Ghanei www.ghanei.net
!= Parallel computing Concurrency == Handling tasks while others are
still running
Blocked by IO Why? Processing takes long
Threads Solutions Processes Coroutines
Code Outline
Simple, sync IO API Threads Preemptive scheduling by OS Unpredictable
execution ordering
IO bound threads
None
CPU bound threads
CPU bound threads
None
Threads release and acquire GIL Global Interpreter Lock The one
thread that has GIL runs at a time
1 CPU bound thread
3 CPU bound threads
Not good for CPU bound Threads Good for user Interactivity,
maybe IO Shared state might cause difficulties
Simple, sync IO API Processes Preemptive scheduling by OS Unpredictable
execution ordering
IO bound processes
CPU bound processes
CPU bound processes
None
Processes Good for parallel processing Use more resources than threads
Shared state might cause difficulties
Predictable execution ordering Coroutines Cooperative concurrency
PEP 380 (yield from) Coroutines Generators (yield) Greenlets (green threads)
CPU bound greenlets
CPU bound greenlets
None
Coroutines Have early results Controlling execution
Async IO No blocking calls Respond to IO Events
Event driven concurrency Callback based (Twisted) Coroutine based (Gevent) Both
(asyncio)
Gevent Implicit coroutines (using greenlets) threading like API Monkey patching
libev event loop
Gevent
None
Twisted Explicit event loop Batteries included Deferreds No blocking calls
Twisted
None
asyncio (tulip) PEP 3156 (asyncio) Callbacks and coroutines API Standard
library Explicit event loop
Thanks