Search code examples
pythoncythongil

Dangers of Releasing the GIL in Cython?


If I choose to release the GIL in a Cython script what considerations do I have to make?

Are there any added dangers or risk to releasing the GIL in a Cython program?

Also how do I specify the number of threads to spawn?


Solution

  • If I choose to release the GIL in a Cython script what considerations do I have to make?

    Are there any added dangers or risk to releasing the GIL in a Cython program?

    You can't safely do anything that does anything interesting with a Python object. You can't safely do anything that touches your object's data without knowing that it's safe (possibly with your own lock).

    https://docs.python.org/2/c-api/init.html#thread-state-and-the-global-interpreter-lock will provide some information.

    Also how do I specify the number of threads to spawn?

    Creating the threads is completely separately. You might do this with the threading module or you might do it any other way.