Summary
In this chapter we have explored the basics of multiprocessing/multithreading applied to a classic embarrassingly parallel problem to discover that the apparently complicated calculations were less of an overhead than the context-switching cost of the parallelization techniques. Then, we discussed the importance of testing thread safety when you work with the threading module or similar. Finally, some of the most interesting well-known problems for which parallelization could offer benefits were mentioned. With these tools, you should be able to evaluate whether a workload is a good fit for the application of such kinds of optimization.
The next chapter will go deeper into practice with the implementation of simple solutions that take advantage of Python’s cooperative multitasking capabilities: generators and coroutines will be used to improve vanilla solutions for a CPU-intensive problem. Those tools, along with those discussed here, form the basis for understanding...