[Numpy-discussion] importing multiarraymodule.c in Python embedding

Steele, Greg gsteele@qualcomm....
Tue Feb 6 18:28:26 CST 2007

I have run into an interesting issue with multiarraymodule.c with
regards to embedding Python in a C application on Windows XP. In the
application, the following abbreviated sequence was executed


1) Py_Initialize

2) numpy is imported

3) Py_Finalize

4) Py_Initialize

5) attempt to import numpy results in an error.


I have tracked this down to two things

1) Python does not call the FreeLibrary windows API on C extension
modules when shutting down

2) multiarraymodule.c has a static variable _multiarray_module_loaded
which, when set, bypasses the call to Py_InitModule


The error at step 5 above occurs because the multiarraymodule DLL is
loaded at step 2, the _multiarray_module_loaded variable is set at step
2, and Py_InitModule is bypassed at step 5. Since Py_InitModule is not
called, multiarraymodule is not placed in the module dictionary (i.e.
sys.modules) and an error occurs in importdl.h which checks if the
module is there.


The obvious solution is to not execute the sequence above.


This issue does seem to highlight a weakness in the implementation of
multiarraymodule.c. Could someone comment on the need for static
variable _multiarray_module_loaded? Is there a more robust way to
achieve the goal?






-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070206/d8ba40f8/attachment.html 

More information about the Numpy-discussion mailing list