[Numpy-discussion] calling _import_array() twice crashes python
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 <firstname.lastname@example.org> 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
> <do something with numpy>
> 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?
> Numpy-discussion mailing list
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
More information about the Numpy-discussion