This chapter covers:
- Using asynchronous processing to allow efficient response to user requests
- Understanding threading in Python, especially its limitations
- Making multi-processing applications that can take full advantage of multi-core computers
Modern CPU architectures allow for more than one sequential program to be executed at the same time, permitting speed ups up to the number of parallel processing units available (e.g. CPU cores). However most Python code is normally sequential, so it is not able to use all available CPU resources. This means that most Python code doesn’t take advantage of modern hardware’s capabilities, and tends to run at a much lower speed than the hardware allow. So we need to devise techniques to get help Python make use of all the available CPU power. In this chapter we are going learn how to do just that, starting with some approaches you may be familiar with in general, but which have some unique Python twists. We will discuss concurrency, multi-threading and parallelism the Python way, including some strong limitations around multi-threaded programming.