Remove trace messages

This commit is contained in:
2023-11-06 23:44:33 +01:00
parent ec68e142ac
commit 472f51daf6
4 changed files with 4 additions and 26 deletions

View File

@@ -1,7 +1,6 @@
#define PY_SSIZE_T_CLEAN
#include <stdexcept>
#include "PyWrap.h"
#include <iostream>
#include <string>
#include <map>
#include <boost/python/numpy.hpp>
@@ -17,32 +16,22 @@ namespace pywrap {
{
std::lock_guard<std::mutex> lock(mutex);
if (wrapper == nullptr) {
std::cout << "Creando instancia" << std::endl;
wrapper = new PyWrap();
pyInstance = new CPyInstance();
std::cout << "Instancia creada" << std::endl;
}
return wrapper;
}
void PyWrap::RemoveInstance()
{
if (wrapper != nullptr) {
std::cout << "Liberando instancia Python Stack" << std::endl;
if (pyInstance != nullptr) {
std::cout << "-Liberando Python => PyHelper" << std::endl;
delete pyInstance;
} else {
std::cout << "*No había instancia de python para liberar. => PyHelper" << std::endl;
}
pyInstance = nullptr;
if (wrapper != nullptr) {
std::cout << "-Liberando PyWrap." << std::endl;
delete wrapper;
} else {
std::cout << "*No había instancia de PyWrap para liberar." << std::endl;
}
wrapper = nullptr;
std::cout << "Instancia liberada" << std::endl;
}
}
void PyWrap::importClass(const std::string& moduleName, const std::string& className)
@@ -53,7 +42,7 @@ namespace pywrap {
}
CPyObject module = PyImport_ImportModule(moduleName.c_str());
if (PyErr_Occurred()) {
errorAbort("Could't import module " + moduleName);
errorAbort("Couldn't import module " + moduleName);
}
CPyObject classObject = PyObject_GetAttrString(module, className.c_str());
if (PyErr_Occurred()) {
@@ -68,17 +57,14 @@ namespace pywrap {
classObject.AddRef();
instance.AddRef();
moduleClassMap.insert({ { moduleName, className }, { module.getObject(), classObject.getObject(), instance.getObject() } });
std::cout << "Clase importada" << std::endl;
}
void PyWrap::clean(const std::string& moduleName, const std::string& className)
{
std::lock_guard<std::mutex> lock(mutex);
std::cout << "Start cleaning " << moduleName << "." << className << std::endl;
auto result = moduleClassMap.find({ moduleName, className });
if (result == moduleClassMap.end()) {
return;
}
std::cout << "--> Cleaning PyObject" << std::endl;
Py_DECREF(std::get<0>(result->second));
Py_DECREF(std::get<1>(result->second));
Py_DECREF(std::get<2>(result->second));
@@ -90,11 +76,10 @@ namespace pywrap {
if (moduleClassMap.empty()) {
RemoveInstance();
}
std::cout << "End Cleaning " << moduleName << "." << className << std::endl;
}
void PyWrap::errorAbort(const std::string& message)
{
std::cout << message << std::endl;
std::cerr << message << std::endl;
PyErr_Print();
RemoveInstance();
exit(1);
@@ -146,7 +131,6 @@ namespace pywrap {
PyObject* PyWrap::predict(const std::string& moduleName, const std::string& className, CPyObject& X)
{
std::cout << "Llamando método predict" << std::endl;
PyObject* instance = getClass(moduleName, className);
PyObject* result;
std::string method = "predict";