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
180
Statsd
farzadghanei
0
110
Introduction to StatsD
farzadghanei
0
200
Other Decks in Programming
See All in Programming
良いユニットテストを書こう
mototakatsu
11
3.5k
React 19でお手軽にCSS-in-JSを自作する
yukukotani
5
530
선언형 UI에서의 상태관리
l2hyunwoo
0
250
Findy Team+ Awardを受賞したかった!ベストプラクティス応募内容をふりかえり、開発生産性向上もふりかえる / Findy Team Plus Award BestPractice and DPE Retrospective 2024
honyanya
0
130
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
1.2k
GitHubで育つ コラボレーション文化 : ニフティでのインナーソース挑戦事例 - 2024-12-16 GitHub Universe 2024 Recap in ZOZO
niftycorp
PRO
0
1k
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
230
php-conference-japan-2024
tasuku43
0
400
rails newと同時に型を書く
aki19035vc
4
570
AWSのLambdaで PHPを動かす選択肢
rinchoku
2
360
MCP with Cloudflare Workers
yusukebe
2
260
ISUCON14感想戦で85万点まで頑張ってみた
ponyo877
0
150
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
244
12k
Adopting Sorbet at Scale
ufuk
74
9.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
850
No one is an island. Learnings from fostering a developers community.
thoeni
19
3.1k
Embracing the Ebb and Flow
colly
84
4.5k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
112
50k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Scaling GitHub
holman
459
140k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Unsuck your backbone
ammeep
669
57k
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