From: sbh Date: Thu, 27 Nov 2014 07:49:19 +0000 (+0300) Subject: Print a message on python plugin import error. X-Git-Tag: V_0.7.0_rc1~57^2~3^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ef9699a42efae36d40f84600ee70603bace65bca;p=modules%2Fshaper.git Print a message on python plugin import error. --- diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index 57f220e4c..27a03156c 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -138,6 +138,24 @@ void Config_ModuleReader::loadScript(const std::string theFileName) /* aquire python thread */ PyGILState_STATE gstate = PyGILState_Ensure(); PyObject* module = PyImport_ImportModule(aPythonFile.c_str()); + + if (!module) { + std::string anErrorMsg = "An error occured while loading " + aPythonFile; + //Get detailed error message: + if (PyErr_Occurred()) { + PyObject *ptype, *pvalue, *ptraceback; + PyErr_Fetch(&ptype, &pvalue, &ptraceback); + std::string aPyError = std::string(PyString_AsString(pvalue)); + if (!aPyError.empty()) { + anErrorMsg += ":\n" + aPyError; + } + Py_XDECREF(ptype); + Py_XDECREF(pvalue); + Py_XDECREF(ptraceback); + } + Events_Error::send(anErrorMsg); + } + /* release python thread */ PyGILState_Release(gstate); }