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
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
120
PHP memory management and garbage collection
farzadghanei
1
270
Some of the ways of gathering information
farzadghanei
0
170
Statsd
farzadghanei
0
110
Introduction to StatsD
farzadghanei
0
190
Other Decks in Programming
See All in Programming
受け取る人から提供する人になるということ
little_rubyist
0
210
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
160
Click-free releases & the making of a CLI app
oheyadam
2
110
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
3
430
[PyCon Korea 2024 Keynote] 커뮤니티와 파이썬, 그리고 우리
beomi
0
120
CSC509 Lecture 09
javiergs
PRO
0
140
Java ジェネリクス入門 2024
nagise
0
700
Macとオーディオ再生 2024/11/02
yusukeito
0
340
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
240
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
310
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
390
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
600
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Building Applications with DynamoDB
mza
90
6.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Building an army of robots
kneath
302
42k
The Language of Interfaces
destraynor
154
24k
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Facilitating Awesome Meetings
lara
50
6.1k
Docker and Python
trallard
40
3.1k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Teambox: Starting and Learning
jrom
133
8.8k
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