O'Reilly logo

Software Architecture with Python by Anand Balachandran Pillai

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Multithreading – Python and GIL

In Python there is, a global lock that prevents multiple threads from executing native bytecode at once. This lock is required, since the memory management of CPython (the native implementation of Python) is not thread-safe.

This lock is called Global Interpreter Lock or just GIL.

Python cannot execute bytecode operations concurrently on CPUs due to the GIL. Hence, Python becomes almost unsuitable for the following cases:

  • When the program depends on a number of heavy bytecode operations, which it wants to run concurrently
  • When the program uses multithreading to utilize the full power of multiple CPU cores on a single machine

I/O calls and long-running operations typically occur outside the GIL. Therefore, multithreading ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required