How is Multithreading achieved in Python?

Although Python includes a multi-threading module, it is generally not recommended for use because it increases code execution time.

  • The Global Interpreter Lock is a function Object() { [native code] } in Python (GIL). Only one of your ‘threads’ may run at a moment, thanks to the GIL. The procedure ensures that each thread obtains the GIL, performs some work, and then passes the GIL to the next thread.

  • This happens in a very short period of time, which is why it appears to the human eye that your threads are running in parallel, but they are actually running one by one, taking turns using the same CPU core.