Python concurrency concepts (like Multiprocessing, Multithreading, Coroutines, Asynchronous I/O ) will be explained in this tutorial. These are very relevant to production level code. If we can can apply these, then in many cases existing codes can be refactored and possibly we can make them simpler, improve response time and overall throughput (wherever applicable like a network server application). The concurrency models are equally important when implementing new applications.

An outline of the tutorial with approximate breakup of time is given below:

Process Based Parallelism (15 mins.)

  • Brief Overview of Process Management in Linux
  • Introduction to multiprocessing module
  • Parallelizing the execution of a function across multiple input values
  • (Data parallelism using pool of worker processes)
  • Communication between Processes - Pipes/Queues
  • Synchronization between processes
  • Sharing data between processes using Shared Memory

Coroutines (10 mins.)

  • Overview of Coroutines
  • Implementing Coroutine like functionality using "Extended Python Generators" (Python 2.5+)
  • Coroutines by leveraging sub generator delegation
  • Coroutines with async/await syntax

ProcessPoolExecutor, ThreadPool Executor (10 mins.)

  • ThreadPoolExecutor
  • ProcessPoolExecutor
  • Future Objects

Asynchronous I/O, event loop, coroutines and tasks (25 mins.)

  • Event Loop
  • Writing single-threaded concurrent code using coroutines
  • Multiplexing I/O access
  • Using Transport and Protocol classes for implementing Client/Server applications

Solving an assignment (30 mins.)

Tanmoy Bandyopadhyay

Affiliation: Aricent

I am having around 19 years of work experience in academics and industry (Aricent, Infosys). I am a post graduate in Information Technology.