I am trying to run a python program from a C program.
However when I add the line import signal in my .py file I get a segmentation fault.
Using GDB I saw that the line pModule = PyImport_Import(pName); returns a NULL value.
(gdb) print pModule
$1 = (PyObject *) 0x0
When I remove the line import signal in python the module loads correctly.
Do you know how to fix this ?
Here is my python code:
import signal
def main(person):
print("DANS PYTHON")
return "What's up " + person;
And here is my C code:
#include <stdio.h>
#include <Python.h>
void main(void) {
Py_Initialize();
PyObject *pName,*pName2, *pModule, *pFunc, *pArgs, *pValue;
PySys_SetPath(L".");
pName = PyUnicode_FromString((char*)"main");
pModule = PyImport_Import(pName);
pFunc = PyObject_GetAttrString(pModule, (char*)"main");
pArgs = Py_BuildValue("(s)",(char *)"137912500");
pValue = PyObject_CallObject(pFunc, pArgs);
Py_Finalize();
return;
}
I am working with Ubuntu 20.04
Thanks in advance for your help
PySys_SetPath(L".")- wait, what? Why are you settingsys.path = ['.']?