numpy / numpy

The fundamental package for scientific computing with Python.
https://numpy.org
Other
27.84k stars 10.01k forks source link

asanyarray becomes None after re-import np in Embedded mode #12305

Open algogavin opened 5 years ago

algogavin commented 5 years ago

The issue occurred in the "python embedded mode" only. Basically my C program will create a new python interpreter for each task, the interpreter will execute the python script(that will use numpy there). For the first task, everything runs fine, but then the following tasks, it will throw an error indicating "NoneType object is not callable" and if I debug the script, it happen with it call "np.mean()"(where inside the function, the first function call is "arr=asanyarray(a)", and the asanyarray is set to "None" somehow.[As a comparison, it's not "None" for the first interpreter.]

I verify that for each new interpreter, it will re-import the numpy(among others) modules and did not see any error reported. Also , if I change the code below:

a = ... //an numpy array b = a.mean(); //this will cause the "None" error

===> a = ...// an numpy array a_2 = np.asanyarray( a ); //this is ok! b = a_2.mean(); // again, "None" error

I suspect there are some initialization routine in numpy.core.numeric was not properly executed when importing, but I don't know how to debug it.

Reproducing code example:

import numpy as np
a = np.array[1.0]
b = a.mean()

Error message:

'NoneType' object is not callable

Numpy/Python version information:

1.15.3

above issue did not occur with numpy 1.6.0 [I have not get a chance to test the numpy package between 1.6 and 1.15]

algogavin commented 5 years ago

after reading the release note, it seems in 1.15.1 it mentioned the Cython 0.28.3 had some issues on module initialization, and (should) upgrade to newer Cython, but it's not yet for "safety".

mattip commented 5 years ago

We don't support numpy re-initialization. For an overview, this search shows 10 issues, some closed with won't-fix, some still open. Maybe when we drop 2.7 support we can hide our global state in a pep 3121 compatible way via PyModule_GetState