[Numpy-discussion] Help with python in C code

santhu kumar mesanthu at gmail.com
Tue Feb 12 17:06:15 EST 2013


Hello all,

I was able to successfully embed python code into C code. The basic
skeleton is something like this :

In C code :
PyObject *pName, *pModule, *pFunc,*pArgs,*pReturn;
 PyArrayObject *cusForce;
Py_Initialize();
import_array(); // required while using numpy arrays in C
        // Call some python code
        // Py_Decref all the used values
        Py_Finalize()

Py_Finalize caused segmentation faults when numpy was one of import modules
[node1:05762] Failing at address: 0x1
[node1:05762] [ 0] /lib64/libc.so.6 [0x3afa630280]
[node1:05762] [ 1]
/usr/lib64/python2.4/site-packages/numpy/core/multiarray.so [0x2b4e950aaf37]
[node1:05762] [ 2]
/usr/lib64/python2.4/site-packages/numpy/core/multiarray.so [0x2b4e950dd1d0]
[node1:05762] [ 3]
/usr/lib64/python2.4/site-packages/numpy/core/multiarray.so [0x2b4e950e22fa]
[node1:05762] [ 4] /usr/lib64/libpython2.4.so.1.0(PyObject_IsTrue+0x37)
[0x2b4e8a683c77]

Which could be avoided by not calling Py_Finalize. But without calling
Py_Finalize(), I am having huge memory leaks
as the process keeps on increasing its memory usage as I see in top.

Is there any clean way of calling Py_Finalize() when using numpy.
Thanks
santhosh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130212/c55df79e/attachment.html>


More information about the NumPy-Discussion mailing list