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
100
PHP memory management and garbage collection
farzadghanei
1
260
Some of the ways of gathering information
farzadghanei
0
160
Statsd
farzadghanei
0
110
Introduction to StatsD
farzadghanei
0
180
Other Decks in Programming
See All in Programming
最近追加した型の紹介とその振り返り
aki19035vc
0
180
Android開発者のための Kotlin Multiplatform入門
ntaro
0
190
Product Management LT会_クアンド新家
shinshin
0
260
유연한 Composable 설계
l2hyunwoo
0
380
CSC307 Lecture 12
javiergs
PRO
0
220
Terraformテスト入門
msato
0
540
スクラムマスターって孤独じゃないですか?
yoshitaroyoyo
1
140
APIのない大学ログインWebサービスをWKWebViewとJavaScriptでアプリ化した話
akidon0000
1
330
SRE チーム立ち上げ前に考えたこと・取り組んだこと / Considerations and Preparations Before Establishing an SRE Team
mackey0225
3
320
わかりやすい正解を捨てて、コトに向き合う - スクラムフェス金沢2024 スポンサーセッション
yusukekokubo
0
170
継続的な活動で築く地方エンジニアの道
myamashii
2
360
feature環境をGitHub ActionsとCloudFormationでいい感じに管理する
nealle
2
310
Featured
See All Featured
Speed Design
sergeychernyshev
9
270
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
44
4.7k
[RailsConf 2023] Rails as a piece of cake
palkan
35
4.4k
Design by the Numbers
sachag
277
18k
Designing for Performance
lara
604
67k
What’s in a name? Adding method to the madness
productmarketing
PRO
21
2.9k
Optimising Largest Contentful Paint
csswizardry
18
2.6k
Building a Modern Day E-commerce SEO Strategy
aleyda
25
6.7k
The Language of Interfaces
destraynor
151
23k
Pencils Down: Stop Designing & Start Developing
hursman
118
11k
Building a Scalable Design System with Sketch
lauravandoore
458
32k
Atom: Resistance is Futile
akmur
261
25k
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