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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Farzad Ghanei
March 15, 2014
Programming
2
10k
Concurrency in Python
Mini PyCon MY 2014
March 2014, Kuala Lumpur
Farzad Ghanei
March 15, 2014
Tweet
Share
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
290
Some of the ways of gathering information
farzadghanei
0
210
Statsd
farzadghanei
0
120
Introduction to StatsD
farzadghanei
0
210
Other Decks in Programming
See All in Programming
Apache Iceberg V3 and migration to V3
tomtanaka
0
130
Fluid Templating in TYPO3 14
s2b
0
120
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
7
2.4k
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
120
Python札幌 LT資料
t3tra
7
1.1k
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
490
SourceGeneratorのススメ
htkym
0
180
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
110
2年のAppleウォレットパス開発の振り返り
muno92
PRO
0
200
AtCoder Conference 2025
shindannin
0
1k
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
110
CSC307 Lecture 06
javiergs
PRO
0
680
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.3k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
170
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1.1k
Mind Mapping
helmedeiros
PRO
0
71
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
160
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
370
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
210
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
420
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