Nesting python + numpy code in C ++ dll callback

I am new to python embedding. I am trying to inject python + numpy code inside a C ++ callback function (inside a dll)

the problem we are facing is the following. if I have:

Py_Initialize();
// some python glue
// python invocation
Py_Finalize();

everything is working fine.

but if I have:

Py_Initialize();
_import_array(); //to initialize numpy C-API
// some python glue + numpy array object creation
// python invocation via PyObject_CallObject()
Py_Finalize();

this happens the second time it reaches _import_array (); (this means it works for the first callback)

If instead I initialize python and numpy only once and terminate in the destructor (thus, not every time during initialization / termination), everything fails when exiting the callback.

The problem here, I think it is numpy, but I do not know how to solve it.

+5
1

, .dll , , .

"++ Singleton DLL":

DLL?

+1

All Articles