F2py GIL Release Function

Is the global blocker (GIL) locked when I call the f2py wrapped function?

(I'm glad to try to open it myself, but I'm not sufficiently aware that the numpy source knows where to start looking) ...

To clarify, a good answer to this question will help me find out where to look for Py_BEGIN_ALLOW_THREADS in the numpy Py_BEGIN_ALLOW_THREADS , or just tell me if the GIL is released (preferably with some evidence).

+4
source share
1 answer

No, f2py by default leaves the GIL in place. However, you can free the GIL by adding the threadsafe directive.

Example:

 subroutine foo(a) !f2py threadsafe !f2py intent(out) :: a integer a a = 5 end subroutine foo 

Now compile it:

 f2py -c -m foo --build-dir test_build foo.f90 

And we can check the source code:

 grep THREAD test_build/src.*/*.c build/src.linux-x86_64-2.7/testmodule.c: Py_BEGIN_ALLOW_THREADS build/src.linux-x86_64-2.7/testmodule.c: Py_END_ALLOW_THREADS 

However, if we repeat the process of deleting the !f2py threadsafe , then the macros for the GIL release will not be included.

+5
source

All Articles