New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LinearNDInterpolator not thread safe #8856
Comments
On first use, the interpolator computes some additional data
structures, which are cached on the interpolator object. This step is
not threadsafe (it should be, need to add locks around this). The crash
goes away if you add `interpolator((0, 0))` before the threaded calls.
|
@pv thanks for the workaround! |
Having looked at this issue for a while, I still fail to see what is being cached on the first call and where. One way to make the OP crash go away is to hold the GIL in the loop over the data points, https://github.com/scipy/scipy/blob/main/scipy/interpolate/interpnd.pyx#L314 So if indeed the culprit is somwhere in Qhull, I actually wonder if it is really correct to call from with nogil or without specialized locks, since the Qhull website has the note (http://qhull.org/html/qh-code.htm#reentrant):
Concluding, ISTM locks need to be added somewhere in Qhull itself or our Cython wrappers. To properly fix this issue, it needs a look from spatial/qhull expert. @tylerjereddy if memory serves, you worked on scipy.spatial, any chance you have a pointer off the top of your head? |
This is actually very crucial information if you want to use this interpolator in any form of parallel computing. For example, if you don't "initialize" it this way when using This should probably be mentioned in the docs. |
LinearNDInterpolator is crashing with a segfault when an instance is being called concurrently.
Steps to reproduce:
I looked at the source code, but can't see anything at the python level that could cause it to not be thread safe. Can it be deeper down in the fortran routines it's calling ? Could it be related to #4763 and #4770 ?
Reproducing code example:
Error message:
Scipy/Numpy/Python version information:
Tested on both python 2.7.5 and python 3.6.3
The text was updated successfully, but these errors were encountered: