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
Web フロントエンドエンジニアに開かれる AI Agent プロダクト開発 - Vercel AI SDK を観察して AI Agent と仲良くなろう! #FEC余熱NIGHT
izumin5210
3
510
あなたとKaigi on Rails / Kaigi on Rails + You
shimoju
0
130
Django Ninja による API 開発効率化とリプレースの実践
kashewnuts
0
1.3k
Server Side Kotlin Meetup vol.16: 内部動作を理解して ハイパフォーマンスなサーバサイド Kotlin アプリケーションを書こう
ternbusty
3
180
Cursorハンズオン実践!
eltociear
2
990
CSC509 Lecture 06
javiergs
PRO
0
260
2分台で1500examples完走!爆速CIを支える環境構築術 - Kaigi on Rails 2025
falcon8823
3
3.6k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
250
その面倒な作業、「Dart」にやらせませんか? Flutter開発者のための業務効率化
yordgenome03
1
120
TFLintカスタムプラグインで始める Terraformコード品質管理
bells17
2
150
SpecKitでどこまでできる? コストはどれくらい?
leveragestech
0
690
CSC305 Lecture 05
javiergs
PRO
0
210
Featured
See All Featured
For a Future-Friendly Web
brad_frost
180
9.9k
Code Review Best Practice
trishagee
72
19k
Building Better People: How to give real-time feedback that sticks.
wjessup
369
20k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Building a Scalable Design System with Sketch
lauravandoore
463
33k
Site-Speed That Sticks
csswizardry
11
890
Reflections from 52 weeks, 52 projects
jeffersonlam
352
21k
Music & Morning Musume
bryan
46
6.8k
Raft: Consensus for Rubyists
vanstee
139
7.1k
Building a Modern Day E-commerce SEO Strategy
aleyda
43
7.7k
A designer walks into a library…
pauljervisheath
209
24k
Mobile First: as difficult as doing things right
swwweet
224
10k
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