Python: Multithreading, Multiprocessing, and the GIL Explained

One of the many things that make Python such a popular and powerful language is that you can easily divide your code into multiple concurrent threads rather easily, take this for example:

from threading import Thread

def thread_func(n):
    print(f"I'm thread number {n}!")

for t in range(4):
    t = Thread(target=thread_func, args=[t])
    t.start()

4 threads! Easy, right?

Well, not exactly.

Continue reading