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
200
Other Decks in Programming
See All in Programming
從零到一:搭建你的第一個 Observability 平台
blueswen
1
940
事業戦略を理解してソフトウェアを設計する
masuda220
PRO
22
6.1k
Cursor AI Agentと伴走する アプリケーションの高速リプレイス
daisuketakeda
1
120
実はすごいスピードで進化しているCSS
hayato_yokoyama
0
120
統一感のある Go コードを生成 AI の力で手にいれる
otakakot
0
3k
Parallel::Pipesの紹介
skaji
2
910
Perlで痩せる
yuukis
1
690
TypeScript LSP の今までとこれから
quramy
1
500
Julia という言語について (FP in Julia « SIDE: F ») for 関数型まつり2025
antimon2
3
960
カクヨムAndroidアプリのリブート
numeroanddev
0
430
ReadMoreTextView
fornewid
1
440
WindowInsetsだってテストしたい
ryunen344
1
170
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
299
21k
Gamification - CAS2011
davidbonilla
81
5.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Six Lessons from altMBA
skipperchong
28
3.8k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
228
22k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
107
19k
Producing Creativity
orderedlist
PRO
346
40k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
52
2.8k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
Testing 201, or: Great Expectations
jmmastey
42
7.5k
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