Search This Blog

Tuesday, July 31, 2012

What does the GIL lock means when I use threads in Python

Looking for a way to introduce parallelism to your code you are quickly going to find that there are two different solutions: either you can use threads or processes.

Although python supports both [1] and [2] models the support for threads has a following warning:

[1] CPython implementation detail: Due to the Global Interpreter Lock, in CPython only one thread can execute Python code at once.

It took me a while to understand what this actualy means. This is a serious limitation for a multithreaded programming and it still exists even in the latest python version 3.x [3]. To better understanding what this means this is an example from one of the links below I found:

The GIL enforces Python's requirement that only a single bytecode operation is executed at a time.



  4. Google search about GIL has many link, I personaly found these very useful

    The section "Write multithreaded or multiprocess code"

  6. These below are a little longer to read but they talk about the problem and around it on a very low level

No comments:

Post a Comment