Multithreading versus multiprocessing
Within this book we haven't really covered multithreading yet, but you have probably seen multithreaded code in the past. The big difference between multithreading and multiprocessing is that with multithreading everything is still executed within a single process. That effectively limits your performance to a single CPU core. It actually limits you even further because the code has to deal with the GIL limitations of CPython.
Note
The GIL is the global lock that Python uses for safe memory access. It is discussed in more detail in Chapter 12, Performance – Tracking and Reducing Your Memory and CPU Usage, about performance.
To illustrate that multithreading code doesn't help performance in all cases and can actually be slightly slower than single threaded code, look at this example:
import datetime import threading def busy_wait(n): while n > 0: n -= 1 if __name__ == '__main__': n = 10000000 start ...