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
280
Some of the ways of gathering information
farzadghanei
0
200
Statsd
farzadghanei
0
110
Introduction to StatsD
farzadghanei
0
210
Other Decks in Programming
See All in Programming
エンジニアとして高みを目指す、 利益を生み出す設計の考え方 / design-for-profit
minodriven
23
12k
オープンソースソフトウェアへの解像度🔬
utam0k
3
280
Playwrightはどのようにクロスブラウザをサポートしているのか
yotahada3
7
2.3k
アメ車でサンノゼを走ってきたよ!
s_shimotori
0
210
CSC509 Lecture 06
javiergs
PRO
0
260
なぜGoのジェネリクスはこの形なのか? Featherweight Goが明かす設計の核心
ryotaros
7
1k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
220
株式会社 Sun terras カンパニーデック
sunterras
0
250
Conquering Massive Traffic Spikes in Ruby Applications with Pitchfork
riseshia
0
160
Catch Up: Go Style Guide Update
andpad
0
200
階層構造を表現するデータ構造とリファクタリング 〜1年で10倍成長したプロダクトの変化と課題〜
yuhisatoxxx
3
950
複雑化したリポジトリをなんとかした話 pipenvからuvによるモノレポ構成への移行
satoshi256kbyte
1
940
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Producing Creativity
orderedlist
PRO
347
40k
Building a Modern Day E-commerce SEO Strategy
aleyda
43
7.7k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
YesSQL, Process and Tooling at Scale
rocio
173
14k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
Side Projects
sachag
455
43k
A designer walks into a library…
pauljervisheath
209
24k
Into the Great Unknown - MozCon
thekraken
40
2.1k
Raft: Consensus for Rubyists
vanstee
139
7.1k
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