SlideShare a Scribd company logo
@adam_englander
Concurrent Programming in
Python
Programming the multi-verse
@adam_englander
Threading
• Thread-Local can be used for global data only accessible by a
single thread.
• Semaphores and locks prevent simultaneous access of memory.
Python’s with statement makes it a lot cleaner than many languages.
• Events and Barriers allow for easy interprocess coordination.
@adam_englander
Processes
• Process class allows for spawning and forking of processes from a
parent process.
• Popular for multi-tasking in scripts as you are simply executing a
command rather Threading which runs code.
• Provides pipes, queues, shared memory, and server processes for
interprocess communication.
• Allows for worker pools to manage resource utilization.
@adam_englander
Subprocesses
• Run other scripts from a main script
• Uses popen to open other scripts
• Allows for better error handling of subscripts
• Allows for waiting on the subscript to complete
@adam_englander
Concurrent
• Uses Futures
• Can use Thread Pools or Process Pools
• Allows for asynchronous function programming
• Works just like any other language with Futures/Promises
@adam_englander
Suggestions
• For scripts, uses Subprocess
• For all but the simplest of applications, use a concurrent framework
like curio, Tornado, Twisted, etc.
@adam_englander
Process Example
from multiprocessing import Process

import os

from random import randint

from time import sleep





def start():

print("Hello from pid", os.getpid())

sleep(randint(1, 3))

print("Goodbye from pid", os.getpid())

exit()



print("Hello from master pid", os.getpid())

for i in range(1, 5):

p = Process(target=start)

p.start()

print("Goodbye from master pid", os.getpid())
@adam_englander
Subprocess Example
import subprocess



print("nnManaged exec error")

p = subprocess.Popen(
[“/not/a/valid/script"],
shell=True,
stderr=subprocess.PIPE)

p.wait()

print(p.returncode, p.stderr.read())
@adam_englander
Curio
• High concurrency framework with no asynchronous I/O
• Utilizes core asynchronous and concurrency libraries available in
Python 3.5+
• Simplifies concurrent programming
• Highly performant
@adam_englander
Demos!
@adam_englander
Resources
• http://curio.readthedocs.io/
• https://docs.python.org/3/library/concurrency.html

More Related Content

PDF
MPI, Erlang and the web
KEY
CPAN Gems From The Far East
PDF
Infinite Topic Backlogs with Apache Pulsar
PPTX
Rust kafka-5-2019-unskip
PDF
Rust with-kafka-07-02-2019
PPT
ruby + websocket + haproxy
PDF
10 Things you should know about Ruby
PPTX
Asynchronous programming using CompletableFutures in Java
MPI, Erlang and the web
CPAN Gems From The Far East
Infinite Topic Backlogs with Apache Pulsar
Rust kafka-5-2019-unskip
Rust with-kafka-07-02-2019
ruby + websocket + haproxy
10 Things you should know about Ruby
Asynchronous programming using CompletableFutures in Java

What's hot (19)

PPTX
Rust programming-language
PDF
Rethinking the debugger
PDF
Stateful stream processing with kafka and samza
ODP
Rust Primer
KEY
Zero mq logs
PDF
Hermes Reliable Replication Protocol - Poster
PDF
Asynchronous web-development with Python
PDF
Asynchronous web-development with Python
PDF
Hermes Reliable Replication Protocol - ASPLOS'20 Presentation
PPTX
Functional Programming in PHP
PPT
easyM2R
PDF
High Performance Systems in Go - GopherCon 2014
PDF
Crafting interactive troubleshooting guides and team documentation for your K...
PPTX
How to Keep Your Data Safe in MongoDB
ODP
Developing high-performance network servers in Lisp
PPTX
Keeping MongoDB Data Safe
PPTX
Designing a Docker Stack for Symfony apps: lessons learned
PPTX
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"
PPT
Debugging rails
Rust programming-language
Rethinking the debugger
Stateful stream processing with kafka and samza
Rust Primer
Zero mq logs
Hermes Reliable Replication Protocol - Poster
Asynchronous web-development with Python
Asynchronous web-development with Python
Hermes Reliable Replication Protocol - ASPLOS'20 Presentation
Functional Programming in PHP
easyM2R
High Performance Systems in Go - GopherCon 2014
Crafting interactive troubleshooting guides and team documentation for your K...
How to Keep Your Data Safe in MongoDB
Developing high-performance network servers in Lisp
Keeping MongoDB Data Safe
Designing a Docker Stack for Symfony apps: lessons learned
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"
Debugging rails
Ad

Similar to Concurrent Programming in Python (20)

PDF
MultiThreading in Python
PDF
concurrency
PDF
Multithreaded_Programming_in_Python.pdf
PPTX
MULTI-THREADING in python appalication.pptx
PDF
Concurrency and Python - PyCon MY 2015
PDF
Parallel programming using python
PDF
Parallel programming using python
PDF
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
PPTX
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
KEY
Do more than one thing at the same time, the Python way
PDF
Concurrency in Python
PDF
Multiprocessing with python
PDF
Intro to Multitasking
PPTX
MULTI THREADING.pptx
PDF
Multiprocessing.pdf..............,.......
PDF
Multiprocessing.............,...........
PPTX
Advanced python
PPTX
Understanding concurrency
PDF
Introduction to Python Asyncio
MultiThreading in Python
concurrency
Multithreaded_Programming_in_Python.pdf
MULTI-THREADING in python appalication.pptx
Concurrency and Python - PyCon MY 2015
Parallel programming using python
Parallel programming using python
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Do more than one thing at the same time, the Python way
Concurrency in Python
Multiprocessing with python
Intro to Multitasking
MULTI THREADING.pptx
Multiprocessing.pdf..............,.......
Multiprocessing.............,...........
Advanced python
Understanding concurrency
Introduction to Python Asyncio
Ad

More from Adam Englander (20)

PPTX
Making PHP Smarter - Dutch PHP 2023.pptx
PDF
Practical API Security - PyCon 2019
PDF
Threat Modeling for Dummies
PDF
ZendCon 2018 - Practical API Security
PDF
ZendCon 2018 - Cryptography in Depth
PDF
Threat Modeling for Dummies - Cascadia PHP 2018
PDF
Dutch PHP 2018 - Cryptography for Beginners
PDF
php[tek] 2108 - Cryptography Advances in PHP 7.2
PDF
php[tek] 2018 - Biometrics, fantastic failure point of the future
PDF
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
PPTX
Practical API Security - PyCon 2018
PDF
Practical API Security - Midwest PHP 2018
PDF
Cryptography for Beginners - Midwest PHP 2018
PDF
Cryptography for Beginners - Sunshine PHP 2018
PDF
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
PDF
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
PDF
ZendCon 2017 - Cryptography for Beginners
PDF
ZendCon 2017: The Red Team is Coming
PDF
ZendCon 2017 - Build a Bot Workshop - Async Primer
PDF
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Making PHP Smarter - Dutch PHP 2023.pptx
Practical API Security - PyCon 2019
Threat Modeling for Dummies
ZendCon 2018 - Practical API Security
ZendCon 2018 - Cryptography in Depth
Threat Modeling for Dummies - Cascadia PHP 2018
Dutch PHP 2018 - Cryptography for Beginners
php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2018 - Biometrics, fantastic failure point of the future
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Practical API Security - PyCon 2018
Practical API Security - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Sunshine PHP 2018
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
ZendCon 2017 - Cryptography for Beginners
ZendCon 2017: The Red Team is Coming
ZendCon 2017 - Build a Bot Workshop - Async Primer
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat

Recently uploaded (20)

PDF
AI in Product Development-omnex systems
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
L1 - Introduction to python Backend.pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
System and Network Administration Chapter 2
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Odoo Companies in India – Driving Business Transformation.pdf
AI in Product Development-omnex systems
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
L1 - Introduction to python Backend.pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
System and Network Administration Chapter 2
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
How Creative Agencies Leverage Project Management Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
2025 Textile ERP Trends: SAP, Odoo & Oracle
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
How to Migrate SBCGlobal Email to Yahoo Easily
PTS Company Brochure 2025 (1).pdf.......
Reimagine Home Health with the Power of Agentic AI​
Which alternative to Crystal Reports is best for small or large businesses.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Odoo Companies in India – Driving Business Transformation.pdf

Concurrent Programming in Python