[Numpy-discussion] numpy threads crash when allocating arrays

Julian Taylor jtaylor.debian at googlemail.com
Tue Jun 14 15:28:42 EDT 2016


On 14.06.2016 19:34, Burlen Loring wrote:

>
> here's my question: given Py_BEGIN_ALLOW_THREADS is used by numpy how
> can numpy be thread safe? and how can someone using the C-API know where
> it's necessary to acquire the GIL? Maybe someone can explain this?
>

numpy only releases the GIL when it is not accessing any python objects 
or other non-threadsafe structures anymore.
That is usually during computation loops and IO.


Your problem is indeed a missing PyGILState_Ensure

I am assuming that the threads you are using are not created by python, 
so you don't have a threadstate setup and no GIL.
You do set it up with that function, see 
https://docs.python.org/2/c-api/init.html#non-python-created-threads



More information about the NumPy-Discussion mailing list