About this ebook
If you are an experienced Python programmer and are willing to utilize the available computing resources by parallelizing applications in a simple way, then this book is for you. You are required to have a basic knowledge of Python development to get the most of this book.
Related to Parallel Programming with Python
Related ebooks
Mastering Objectoriented Python Rating: 5 out of 5 stars5/5Python Parallel Programming Cookbook Rating: 5 out of 5 stars5/5Python Unlocked Rating: 0 out of 5 stars0 ratingsPython 3 Object-oriented Programming - Second Edition Rating: 4 out of 5 stars4/5Python In - Depth: Use Python Programming Features, Techniques, and Modules to Solve Everyday Problems Rating: 0 out of 5 stars0 ratingsModular Programming with Python Rating: 0 out of 5 stars0 ratingsLearning Python Application Development Rating: 0 out of 5 stars0 ratingsPython Data Structures and Algorithms Rating: 5 out of 5 stars5/5Learning Python Network Programming Rating: 5 out of 5 stars5/5Scientific Computing with Python 3 Rating: 0 out of 5 stars0 ratingsGetting Started with Python Data Analysis Rating: 0 out of 5 stars0 ratingsLearn Multithreading with Modern C++ Rating: 0 out of 5 stars0 ratingsPython Data Analysis - Second Edition Rating: 0 out of 5 stars0 ratingsPython 3 Object Oriented Programming Rating: 4 out of 5 stars4/5Functional Python Programming Rating: 0 out of 5 stars0 ratingsNumPy Essentials Rating: 0 out of 5 stars0 ratingsPython Data Visualization Cookbook Rating: 4 out of 5 stars4/5Learning Flask Framework Rating: 4 out of 5 stars4/5Advance Core Python Programming: Begin your Journey to Master the World of Python (English Edition) Rating: 4 out of 5 stars4/5Mastering Python Design Patterns Rating: 0 out of 5 stars0 ratingsGetting Started with Beautiful Soup Rating: 3 out of 5 stars3/5NumPy Beginner's Guide Rating: 5 out of 5 stars5/5Building Machine Learning Systems with Python Rating: 4 out of 5 stars4/5Building RESTful Python Web Services Rating: 4 out of 5 stars4/5
Trending on #Booktok
A Court of Mist and Fury Rating: 5 out of 5 stars5/5Icebreaker: A Novel Rating: 4 out of 5 stars4/5It Ends with Us: A Novel Rating: 4 out of 5 stars4/5The Assassin and the Pirate Lord: A Throne of Glass Novella Rating: 4 out of 5 stars4/5The Secret History: A Read with Jenna Pick: A Novel Rating: 4 out of 5 stars4/5Powerless Rating: 4 out of 5 stars4/5A Little Life: A Novel Rating: 4 out of 5 stars4/5Pride and Prejudice Rating: 4 out of 5 stars4/5Normal People: A Novel Rating: 4 out of 5 stars4/5The Love Hypothesis Rating: 4 out of 5 stars4/5If We Were Villains: A Novel Rating: 4 out of 5 stars4/5The Summer I Turned Pretty Rating: 4 out of 5 stars4/5Funny Story Rating: 4 out of 5 stars4/5Happy Place Rating: 4 out of 5 stars4/5Once Upon a Broken Heart Rating: 4 out of 5 stars4/5Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones Rating: 4 out of 5 stars4/5Seven Stones to Stand or Fall: A Collection of Outlander Fiction Rating: 4 out of 5 stars4/5Better Than the Movies Rating: 4 out of 5 stars4/5Fire & Blood: 300 Years Before A Game of Thrones Rating: 4 out of 5 stars4/5The 48 Laws of Power Rating: 4 out of 5 stars4/5Crime and Punishment Rating: 4 out of 5 stars4/5Beauty and the Beast Rating: 4 out of 5 stars4/5Dune Rating: 4 out of 5 stars4/5Divine Rivals: A Novel Rating: 4 out of 5 stars4/5Rich Dad Poor Dad Rating: 4 out of 5 stars4/5The Lord Of The Rings: One Volume Rating: 5 out of 5 stars5/5The Little Prince: New Translation Version Rating: 5 out of 5 stars5/5Finnegans Wake Rating: 4 out of 5 stars4/5Beach Read Rating: 4 out of 5 stars4/5Milk and Honey: 10th Anniversary Collector's Edition Rating: 4 out of 5 stars4/5
Reviews for Parallel Programming with Python
0 ratings0 reviews
Book preview
Parallel Programming with Python - Jan Palach
Table of Contents
Parallel Programming with Python
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Contextualizing Parallel, Concurrent, and Distributed Programming
Why use parallel programming?
Exploring common forms of parallelization
Communicating in parallel programming
Understanding shared state
Understanding message passing
Identifying parallel programming problems
Deadlock
Starvation
Race conditions
Discovering Python's parallel programming tools
The Python threading module
The Python multiprocessing module
The parallel Python module
Celery – a distributed task queue
Taking care of Python GIL
Summary
2. Designing Parallel Algorithms
The divide and conquer technique
Using data decomposition
Decomposing tasks with pipeline
Processing and mapping
Identifying independent tasks
Identifying the tasks that require data exchange
Load balance
Summary
3. Identifying a Parallelizable Problem
Obtaining the highest Fibonacci value for multiple inputs
Crawling the Web
Summary
4. Using the threading and concurrent.futures Modules
Defining threads
Advantages and disadvantages of using threads
Understanding different kinds of threads
Defining the states of a thread
Choosing between threading and _thread
Using threading to obtain the Fibonacci series term with multiple inputs
Crawling the Web using the concurrent.futures module
Summary
5. Using Multiprocessing and ProcessPoolExecutor
Understanding the concept of a process
Understanding the process model
Defining the states of a process
Implementing multiprocessing communication
Using multiprocessing.Pipe
Understanding multiprocessing.Queue
Using multiprocessing to compute Fibonacci series terms with multiple inputs
Crawling the Web using ProcessPoolExecutor
Summary
6. Utilizing Parallel Python
Understanding interprocess communication
Exploring named pipes
Using named pipes with Python
Writing in a named pipe
Reading named pipes
Discovering PP
Using PP to calculate the Fibonacci series term on SMP architecture
Using PP to make a distributed Web crawler
Summary
7. Distributing Tasks with Celery
Understanding Celery
Why use Celery?
Understanding Celery's architecture
Working with tasks
Discovering message transport (broker)
Understanding workers
Understanding result backends
Setting up the environment
Setting up the client machine
Setting up the server machine
Dispatching a simple task
Using Celery to obtain a Fibonacci series term
Defining queues by task types
Using Celery to make a distributed Web crawler
Summary
8. Doing Things Asynchronously
Understanding blocking, nonblocking, and asynchronous operations
Understanding blocking operations
Understanding nonblocking operations
Understanding asynchronous operations
Understanding event loop
Polling functions
Using event loops
Using asyncio
Understanding coroutines and futures
Using coroutine and asyncio.Future
Using asyncio.Task
Using an incompatible library with asyncio
Summary
Index
Parallel Programming with Python
Parallel Programming with Python
Copyright © 2014 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: June 2014
Production reference: 1180614
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78328-839-7
www.packtpub.com
Cover image by Lis Marie Martini (<[email protected]>)
Credits
Author
Jan Palach
Reviewers
Cyrus Dasadia
Wei Di
Michael Galloy
Ludovic Gasc
Kamran Hussain
Bruno Torres
Commissioning Editor
Rebecca Youé
Acquisition Editor
Llewellyn Rozario
Content Development Editor
Sankalp Pawar
Technical Editors
Novina Kewalramani
Humera Shaikh
Copy Editors
Roshni Banerjee
Sarang Chari
Gladson Monteiro
Project Coordinator
Lima Danti
Proofreaders
Simran Bhogal
Maria Gould
Paul Hindle
Indexers
Mehreen Deshmukh
Rekha Nair
Tejal Soni
Priya Subramani
Graphics
Disha Haria
Abhinash Sahu
Production Coordinator
Saiprasad Kadam
Cover Work
Saiprasad Kadam
About the Author
Jan Palach has been a software developer for 13 years, having worked with scientific visualization and backend for private companies using C++, Java, and Python technologies. Jan has a degree in Information Systems from Estácio de Sá University, Rio de Janeiro, Brazil, and a postgraduate degree in Software Development from Paraná State Federal Technological University. Currently, he works as a senior system analyst at a private company within the telecommunication sector implementing C++ systems; however, he likes to have fun experimenting with Python and Erlang—his two technological passions. Naturally curious, he loves challenges and learning new technologies, meeting new people, and learning about different cultures.
Acknowledgments
I had no idea how hard it could be to write a book with such a tight deadline among so many other things taking place in my life. I had to fit the writing into my routine, taking care of my family, karate lessons, work, Diablo III, and so on. The task was not easy; however, I got to the end of it hoping that I have generated quality content to please most readers, considering that I have focused on the most important thing based on my experience.
The list of people I would like to acknowledge is so long that I would need a book only for this. So, I would like to thank some people I have constant contact with and who, in a direct or indirect way, helped me throughout this quest.
My wife Anicieli Valeska de Miranda Pertile, the woman I chose to share my love with and gather toothbrushes with to the end of this life, who allowed me to have the time to create this book and did not let me give up when I thought I could not make it. My family has always been important to me during my growth as a human being and taught me the path of goodness.
I would like to thank Fanthiane Ketrin Wentz, who beyond being my best friend is also guiding me through the ways of martial arts, teaching me the values I will carry during a lifetime—a role model for me. Lis Marie Martini, dear friend who provided the cover for this book, and who is an incredible photographer and animal lover.
Big thanks to my former English teacher, reviser, and proofreader, Marina Melo, who helped along the writing of this book. Thanks to the reviewers and personal friends, Vitor Mazzi and Bruno Torres, who contributed a lot to my professional growth and still do.
Special thanks to Rodrigo Cacilhas, Bruno Bemfica, Rodrigo Delduca, Luiz Shigunov, Bruno Almeida Santos, Paulo Tesch (corujito), Luciano Palma, Felipe Cruz, and other people with whom I often talk to about technology. A special thanks to Turma B.
Big thanks to Guido Van Rossum for creating Python, which transformed programming into something pleasant; we need more of this stuff and less set/get.
About the Reviewers
Cyrus Dasadia has worked as a Linux system administrator for over a decade for organizations such as AOL and InMobi. He is currently developing CitoEngine, an open source alert management service written entirely in Python.
Wei Di is a research scientist at eBay Research Labs, focusing on advanced computer vision, data mining, and information retrieval technologies for large-scale e-commerce applications. Her interest covers large-scale data mining, machine learning in merchandising, data quality for e-commerce, search relevance, and ranking and recommender systems. She also has years of research experience in pattern recognition and image processing. She received her PhD from Purdue University in 2011 with focuses on data mining and image classification.
Michael Galloy works as a research mathematician for Tech-X Corporation involved in scientific visualizations using IDL and Python. Before that, he worked for five years teaching all levels of IDL programming and consulting for Research Systems, Inc. (now Exelis Visual Information Solutions). He is the author of Modern IDL (modernidl.idldev.com) and is the creator/maintainer