Chapter 5. Multithreading versus Multiprocessing
When it comes to optimizing code, concurrency and parallelism are two topics that are rarely left out of the conversation. However, in the case of Python these are topics that are normally used to criticize the language. Critics normally blame the difficulty of using these mechanics versus the actual benefit they bring to the table (which, in some instances, is nonexistent).
In this chapter, we will see that the critics are right some of the time and wrong in other cases. Just like with most tools, these mechanics require certain conditions to work for the developer, instead of working against them. During our tour of the internals of how we can achieve parallelism in Python and on which occasions it is actually worth it, we'll discuss two specific topics:
- Multithreading: This is the most classical approach in trying to achieve true parallelism. Other languages such as C++ and Java provide this feature as well.
- Multiprocessing...