On Nov 13, 2009, at 11:23 AM, Robin wrote: > Hi, > > I'm trying to embed Python in a MATLAB mex file. I've been coming > under some pressure to make my Python code available to my MATLAB > colleagues so I am trying to come up with a relatively general way of > calling numerical python code from Matlab. > > I am making some progress - but get a reliable crash from numpy. This > only occurs the second time I am loading it. So I Py_Initialize, > import numpy, Py_Finalize (all works fine), but then if I clear the > mex file (clear funcname in matlab - which calls Py_Finalize through a > mexAtExit handler) and try to run the function again (which will > reinitialize interpreter and import numpy again) I get the followin > stack trace from multisarray.so. Wondered if anyone could through any > light. I have already run into this bug > http://bugs.python.org/issue6869 which prevents me using ctypes... I > wondered if this was related. > > For now its not such a big problem - I will just avoid unloading the > mex function (with clear function). But I thought it might be > indicative of a memory leak or some other problem since I think in > theory it should work (It does if numpy isn't imported).
I wonder if this is related to the fact that you can't "unload" a dynamically linked module (like NumPy has). So, when you call Py_Finalize you are not really "finalizing" your usage of Python extension modules. I'm not sure though. -Travis _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion