In this chapter, we will take a look at generators, coroutines, and parallel processing. Specifically, we will cover the following topics:
- How iteration works in Python
- Using the itertools module
- Using generator functions
- Simulating multithreading with coroutines
- When to use parallel processing
- Forking processes
- How to implement multithreading
- How to implement multiprocessing
Although the various topics that will be covered in this chapter may seem to have little to do with each other, they do have an effect on one another. First, iteration is the process of walking through a sequence; Python provides several ways to iterate over objects. Generators are functions that generate values in a sequential order, implementing iteration functionality under the hood.
This moves into parallelism. Coroutines use generators to effectively create multiple processes to allow multitasking but it is controlled by the programmer. Multithreading switches processing...