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
[The good news is that] modern CPU architectures allow for more than one sequential program to be executed at the same time, permitting [impressive processing speeds. In fact, speeds can increase right up] to the number of parallel processing units (e.g. CPU cores) that are available. [The bad news is that to take advantage of all this parallel processing speed, we need to write parallel code, and Python is ill-suited for writing parallel code.] Most Python code is [sequential], so it is not able to use all the available CPU resources. [In other words, our usual python code cannot make use of] modern hardware’s capabilities, and our solution will run at a much lower speed than the hardware allows. So we need to devise techniques to 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.