[NumPy-Tickets] [NumPy] #2022: Allow user extensions of numpy to run without the GIL but occasionally grab it

NumPy Trac numpy-tickets@scipy....
Wed Jan 18 11:45:45 CST 2012


#2022: Allow user extensions of numpy to run without the GIL but occasionally grab
it
-------------------------+--------------------------------------------------
 Reporter:  irving       |       Owner:  somebody   
     Type:  enhancement  |      Status:  new        
 Priority:  normal       |   Milestone:  Unscheduled
Component:  Other        |     Version:  1.6.1      
 Keywords:               |  
-------------------------+--------------------------------------------------
 Currently numpy supports two execution modes for the execution of
 extension code: with the Python API (and GIL) and entirely without.
 However, a reasonable middle ground is code that runs without accessing
 the Python API most of the time, but occasionally needs to grab access,
 for example to set a Python exception.  While in the current version of
 numpy it is possible to set the "no api" flag and explicitly grab the GIL
 if access is needed, the resulting behavior is broken since numpy does not
 check for any resulting exceptions.

 The easiest fix for this problem is simply to check for exceptions
 regardless if the user code claims to need the Python API, as in this
 patch:

 https://github.com/girving/numpy/commit/730b05a892371d6f18d9317e5ae6dc306c0211b0

 However, such a modification would conflict with any future modifications
 of numpy to parallelize array operations over multiple threads.
 Therefore, I propose a pair of numpy api functions which acquire and
 release the GIL safely from inside numpy loop code.  The semantics of
 these functions would be the same as PyGILState_Ensure/Release, but would
 work correctly even if called from a non-Python thread created by numpy
 for parallelization purposes.

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/2022>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list