[Numpy-discussion] Dynamic module not initialized properly

Mark Janikas mjanikas@esri....
Mon Apr 2 11:46:22 CDT 2007

Thanks for the info Greg.   Yup.  I am sorry that I had to post a thread
without code to back it up.... unfortunately, there just isn't a way for
me to roll it into an example without the entire package being
installed.  This is all very good info you have provided.  Ill let you
know how things work out.  Thanks again,





From: numpy-discussion-bounces@scipy.org
[mailto:numpy-discussion-bounces@scipy.org] On Behalf Of Steele, Greg
Sent: Monday, April 02, 2007 9:07 AM
To: Discussion of Numerical Python
Subject: Re: [Numpy-discussion] Dynamic module not initialized properly




It is hard to comment since you have not provided much information. Your
link to a previous thread brought up a post that I had sent. The issue
that I encountered had to do with the "multiarraymodule.c" extension
module. When "numpy" is imported, it imports this module and the static
variable "_multiarray_module_loaded" gets set. When Python is finalized
is does not unload the multiarraymodule.c DLL. When Python is
initialized again and "numpy" is imported again, the static variable is
already set and multiarraymodule does not import correctly. Hence the


The way I dealt with this is a 'hack', but it worked for us. This was on
a windows platform. After I finalize Python, I forcibly unload the
multiarraymodule DLL using the "FreeLibrary" call. The C code looks like


    if (multiarray_loaded) {







The two calls of FreeLibrary are needed since each call to LoadLibraryEx
increments the DLL reference count. The call to LoadLibraryEx here gets
a handle to the DLL. 


What needs to be done long term is the removal of the static variable in
multiarraymodule. I don't understand the code well enough to know why it
is needed, but that appears to be the crux of the issue. Another
solution would be for Python to call FreeLibrary on all the DLLs during




From: numpy-discussion-bounces@scipy.org
[mailto:numpy-discussion-bounces@scipy.org] On Behalf Of Mark Janikas
Sent: Friday, March 30, 2007 4:55 PM
To: Discussion of Numerical Python
Subject: [Numpy-discussion] Dynamic module not initialized properly


Hello all,


I am having an issue importing numpy on subsequent (I.e. not on first
load) attempts in our software.  The majority of the code is written in
C, C++ and I am a python developer and do not have direct access to a
lot of it.  This is a bit of a difficult question to ask all of you
because I cant provide you a direct example.  All I can do is point to a
numpy thread that discusses the issue:





exceptions.SystemError: dynamic module not initialized properly


 What is really odd about my specific issue is that if I don't change
anything in the source code.... Then the error doesn't pop up.
Furthermore, the error doesn't show on some attempts even after I make a
change!!!!  Not sure whether there is anything I can do from the
scripting side (some alternative form of reload?)... or if I have to
forward it along to the C developers.  You have my appreciation ahead of


Mark Janikas

Product Engineer

ESRI, Geoprocessing

380 New York St.

Redlands, CA 92373

909-793-2853 (2563)



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

More information about the Numpy-discussion mailing list