[Python-Dev] GIL removal question

Sturla Molden sturla at molden.no
Sun Aug 14 03:53:15 CEST 2011


Den 13.08.2011 17:43, skrev Antoine Pitrou:
> These days we have PyGILState_Ensure():
> http://docs.python.org/dev/c-api/init.html#PyGILState_Ensure
>
With the most recent Cython (0.15) we can just do:

    with gil:
<suite>

to ensure holding the GIL.

And similarly from a thread holding the GIL

    with nogil:
<suite>

to temporarily release it.

There are also some OpenMP support in Cython 0.15. OpenMP is much easier 
than messing around with threads manually (it moves all the hard parts 
of multithreading to the compiler). Now Cython almost makes it look 
Pythonic:

http://docs.cython.org/src/userguide/parallelism.html


Sturla




More information about the Python-Dev mailing list