Py_initialize / Py_Finalize not working twice with numpy

前端 未结 2 929
轮回少年
轮回少年 2020-11-29 11:14

On the second call of the following code, my app segfault, so I guess I am missing something :

Py_Initialize();
pName = PyString_FromString(\"comp_macbeth\")         


        
相关标签:
2条回答
  • 2020-11-29 11:33

    I have this in my module initialization part, but the URL does not exist anymore. In case it helps:

    // http://numpy.scipy.org/numpydoc/numpy-13.html mentions this must be done in module init, otherwise we will crash
    import_array();
    
    0 讨论(0)
  • 2020-11-29 11:59

    From the Py_Finalize docs:

    Some extensions may not work properly if their initialization routine is called more than once; this can happen if an application calls Py_Initialize() and Py_Finalize() more than once.

    Apparently Numpy is one of those. See also this message from Numpy-discussion.

    Calling Py_Initialize() only once, and cleaning up at exit, is the way to go. (And it's should be faster, too!)

    0 讨论(0)
提交回复
热议问题