Through a code written in C++ code that embeds python call external python class and execute a method of the class (FileHandler). That works. I generate a library of that code in C++ (libSome.so) for use in python with c_types and making a wrapper to try to run the above method gives segmentation fault. Any ideas?
(C++)This is the embedded code then generated as a shared library (libSome.so):
...
    /* Funcion de python */
        setenv("PYTHONPATH", ".", 1);
        Py_Initialize();
        PyObject* module = PyImport_ImportModule("filehandler");
        assert(module != NULL);
        PyObject* class = PyObject_GetAttrString(module, "FileHandler");
        assert(class != NULL);
        PyObject* inst = PyInstance_New(class, NULL, NULL);
        assert(inst != NULL);
        result = PyObject_CallMethod(inst, (char*)"write", (char*)"(iiii)",ori,serv, id, timeStamp);
        assert(result != NULL);
        Py_Finalize();
(Python) Code used by the library
import os
class FileHandler:
     def __init__(self):
          self.workingDirectory = os.getcwd()
          pass
     def write(self, NodoOrigen, Servicio, Id, payload):
          try:
           os.mkdir(str(NodoOrigen))
          except:
           pass
      os.chdir(str(NodoOrigen)+"/")
      try:
           os.mkdir(str(Servicio))
      except:
           pass
      os.chdir(self.workingDirectory)
      os.chdir(str(NodoOrigen)+"/"+str(Servicio)+"/")
      try:
           f = open(str(Id),"a")        
      except:
           print "No se puede abrir el archivo"
      f.write(str(payload))
      f.close()
      os.chdir(self.workingDirectory)
 
     
    