Member-only story
Demystifying Python Multiprocessing and Multithreading
…and the Global Interpreter Lock
TLDR: You should use threading if your program is network-bound or multiprocessing if it is CPU-bound.
Personally, I’ve tried to understand multiprocessing and multithreading multiple times over the years but have always failed to fully grasp these concepts. To do so, we need to understand several important terminologies and also something that is unique to the Python programming language — the Global Interpreter Lock (GIL).
If you already know these terminologies, feel free to skip to the next section.
Terminologies
Core: The CPU’s processor. This term refers to the hardware component of your CPU. A core can work on a single task; multi-core processors can perform multiple tasks at once.
Thread: Refers to the virtual component that manages the tasks. Each CPU core can have up to two threads if your CPU has multi/hyper-threading enabled. You can search for your own CPU processor to find out more. For Mac users, you can find out from About > System Report. This means that my 6-Core i7 processor has 6 cores and can have up to 12 threads.