12

I have found several SO questions asking about this in one way or another, but none of them actually either give a list or refer to one.

This question refers to a wiki page, but while the wiki page talks about the GIL and multi-threading, it doesn't give a list of GIL releasing functions.

This mailing list post indicates that the only way to find out is to read the numpy source. Really?

Community
  • 1
  • 1
DanielSank
  • 3,303
  • 3
  • 24
  • 42

1 Answers1

2

It's not guaranteed to catch everything, but I just ran:

git grep nogil

in my clone of the numpy repository. It turns up 82 usages in 2 files:

  • random/mtrand/mtrand.pyx
  • random/mtrand/numpy.pxd
perimosocordiae
  • 17,287
  • 14
  • 60
  • 76
  • 4
    The C thing for releasing the GIL is Py_BEGIN_ALLOW_THREADS, if you want to look for that too. – user2357112 Jun 03 '14 at 20:52
  • This answer basically is "read the source." Is that really the only option? – DanielSank Jun 03 '14 at 20:52
  • 3
    Numpy is an open-source project... If you're feeling philanthropic, you could add this information to the [documentation](https://github.com/numpy/numpy/tree/master/doc) and submit a pull request, so no one else has to read the source! – Benjamin Hodgson Jun 03 '14 at 21:36
  • 5
    Actually numpy has its own macros for releasing the GIL, they are defined [here](https://github.com/numpy/numpy/blob/master/numpy/core/include/numpy/ndarraytypes.h#L931). Grepping for `THREADS` should cover all of the cases. – Jaime Jun 03 '14 at 22:52
  • 3
    @Jaime beware that linking to a code line in GitHub means that your link stops making sense when the code changes and the line numbered in the link is no longer the same code you originally wanted to point to. It's better to link to a code line *within a specific commit* so that it can't ever change. – DanielSank Jan 11 '18 at 06:32