This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyArray_FromAny tries to deallocate double: 12 (d)
Type: Stage:
Components: Versions:
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: Il_Fox, josh.r, scoder
Priority: normal Keywords:

Created on 2014-09-09 18:28 by Il_Fox, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg226655 - (view) Author: Riccardo (Il_Fox) Date: 2014-09-09 18:28
Hi,
I found this strange behaviour of PyArray_FromAny that manifest only inside a parallel region of openmp.
I am using python 2.7.4 and numpy 1.8.0

*** Reference count error detected
an attempt was made to deallocate 12 (d) ***
and this is due to the PyArray_FromAny function that apparently does something also to the reference of NPY_DOUBLE or invisibly uses some kind of global variable generating race condition in a parallel implementation?
If i insert PyArray_FromAny in a critical region the error never pops up.

Best Regards,
Riccardo

P.s. i tried to send you more details and a piece of code but some characters are not accepted by your e-mail, ask me if you want more details
msg226669 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2014-09-10 00:46
This sounds like a bug in Numpy. You should probably post it to their tracker: https://github.com/numpy/numpy/issues
msg226677 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2014-09-10 03:50
Agreed that it's not a bug in CPython, but my guess is that it's not a bug in NumPy either. The C function you call (which IIRC creates a new NumPy array) almost certainly needs the GIL to protect it against race conditions, and since you mentioned OpenMP, you most likely released the GIL. So, just re-acquire the GIL around the call (and make sure you don't have any other threading problems in your code).
msg226687 - (view) Author: Riccardo (Il_Fox) Date: 2014-09-10 08:53
Great, i solved trying to avoid calls to python code in parallel regions.
Thanks for pointing me in right direction, i wasn’t thinking at all to the GIL, i was convinced i had tryed everything and that it was a bug..

Regards

On 10 Sep 2014, at 05:50, Stefan Behnel <report@bugs.python.org> wrote:

> 
> Stefan Behnel added the comment:
> 
> Agreed that it's not a bug in CPython, but my guess is that it's not a bug in NumPy either. The C function you call (which IIRC creates a new NumPy array) almost certainly needs the GIL to protect it against race conditions, and since you mentioned OpenMP, you most likely released the GIL. So, just re-acquire the GIL around the call (and make sure you don't have any other threading problems in your code).
> 
> ----------
> nosy: +scoder
> 
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue22373>
> _______________________________________
History
Date User Action Args
2022-04-11 14:58:07adminsetgithub: 66567
2014-09-10 08:53:03Il_Foxsetmessages: + msg226687
2014-09-10 03:50:04scodersetnosy: + scoder
messages: + msg226677
2014-09-10 02:58:53benjamin.petersonsetstatus: open -> closed
resolution: third party
2014-09-10 00:46:31josh.rsetnosy: + josh.r
messages: + msg226669
2014-09-09 18:28:41Il_Foxcreate