Summary
We have covered many different topics in this chapter, so let’s summarize them:
- What the Python GIL is, why we need it, and how we can work around it
- When to use threads, when to use processes, and when to use
asyncio
- Running code in parallel threads using
threading
andconcurrent.futures
- Running code in parallel processes using
multiprocessing
andconcurrent.futures
- Running code distributed across multiple machines
- Sharing data between threads and processes
- Thread safety
- Deadlocks
The most important lesson you can learn from this chapter is that the synchronization of data between threads and processes is really slow. Whenever possible, you should only send data to the function and return once it is done, with nothing in between. Even in that case, if you can send less data, send less data. If possible, keep your calculations and data local.
In the next chapter, we will learn about scientific Python...