[Numpy-discussion] calling _import_array() twice crashes python
Lisandro Dalcin
dalcinl@gmail....
Thu Mar 5 01:12:38 CST 2009
In general, using complex extension modules like numpy between
matching pairs of Py_Initialize()/Py_Finalize() is tricky...
Extension modules have to be VERY carefully written as to permit such
usage pattern... It is too easy to forget the init/cleanup/finalize
steps... I was able to manage this in one of my projects (mpi4py), but
my package is by far simpler than numpy ...
Do Octave have something like Python's Py_AtExit()? Then you should be
able to register a callback to call Py_Finalize() only once, at the
very end of your Octave process... Regarding initialization, you can
call Py_Initialize() as many times as you want... if Python is already
initialized, Py_Initialize() is a non-op ...
Moreover, such approach is going to be much faster... No need to
reinitialize the full Python runtime every time you want to run some
(possibly tiny) piece of Python code ...
On Wed, Mar 4, 2009 at 11:01 AM, Soeren Sonnenburg <python-ml@nn7.de> wrote:
> Dear all,
>
> I've written a wrapper enabling to run python code from within octave
> (and vice versa). To this end I am embedding python in octave. So I am
> calling
>
> Py_Initialize();
> _import_array();
> <do something with numpy>
> Py_Finalize();
>
> multiple times. While things work nicely on the first run, I am getting
> a crash on _import_array() on the second run...
>
> Is there any cleanup function I should potentially call that would
> prevent this?
>
> Soeren
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
--
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
More information about the Numpy-discussion
mailing list