- Applied Matteo`s tips to the error handling code. Now all loading errors whould be handled. Don`t know about runtime errors, though
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@832 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
6911676b53
commit
addad6aa26
|
@ -35,32 +35,13 @@ using namespace std;
|
||||||
PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyException)
|
PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyException)
|
||||||
: _upolicy_dict(NULL), _adapter(NULL), _name(name)
|
: _upolicy_dict(NULL), _adapter(NULL), _name(name)
|
||||||
{
|
{
|
||||||
//PyRun_SimpleString("import StringIO\nimport sys\nsys.stderr = cStringIO.StringIO()\n");
|
|
||||||
|
|
||||||
//PyObject* pBuiltinsMod = PyImport_ImportModule("__builtin__");
|
|
||||||
//PyObject* pBuiltinsDict = PyModule_GetDict(pBuiltinsMod);
|
|
||||||
|
|
||||||
|
|
||||||
PyObject* pLoadmeStr = PyString_FromString(name);
|
PyObject* pLoadmeStr = PyString_FromString(name);
|
||||||
PyObject* pUserCPUPolicyModule = PyImport_Import(pLoadmeStr);
|
PyObject* pUserCPUPolicyModule = PyImport_Import(pLoadmeStr);
|
||||||
Py_DECREF(pLoadmeStr);
|
Py_DECREF(pLoadmeStr);
|
||||||
|
|
||||||
if( !pUserCPUPolicyModule )
|
if(pUserCPUPolicyModule == NULL)
|
||||||
{
|
throw MalformedPolicyException(get_exception_information().c_str());
|
||||||
PyErr_Print(); // Error in import
|
|
||||||
|
|
||||||
|
|
||||||
// PyObject* msg = PyRun_String("import sys\nsys.stderr.getvalue()", Py_eval_input, pBuiltinsDict, NULL);
|
|
||||||
|
|
||||||
|
|
||||||
// if(msg == NULL)
|
|
||||||
// PyErr_Print();
|
|
||||||
|
|
||||||
// char* str = PyString_AsString(msg);
|
|
||||||
// throw MalformedPolicyException(PyString_AS_STRING(msg));
|
|
||||||
throw MalformedPolicyException("");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dictionary with defined ``symbols'' for .pyc file
|
// Dictionary with defined ``symbols'' for .pyc file
|
||||||
_upolicy_dict = PyModule_GetDict(pUserCPUPolicyModule);
|
_upolicy_dict = PyModule_GetDict(pUserCPUPolicyModule);
|
||||||
assert(_upolicy_dict);
|
assert(_upolicy_dict);
|
||||||
|
@ -89,12 +70,8 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyExceptio
|
||||||
Py_DECREF(pScriptAdapterModule);
|
Py_DECREF(pScriptAdapterModule);
|
||||||
|
|
||||||
if(_adapter == NULL)
|
if(_adapter == NULL)
|
||||||
{
|
throw MalformedPolicyException(get_exception_information().c_str());
|
||||||
PyErr_Print();
|
|
||||||
throw MalformedPolicyException(_("unable to instantiate ScriptAdapter, "
|
|
||||||
"check that all methods are implemented"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// And now, who's your daddy, huh?
|
// And now, who's your daddy, huh?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,8 +189,8 @@ PythonCPUPolicy::wait_unlock() const throw(UserInterruptException)
|
||||||
PyEval_RestoreThread(_save);
|
PyEval_RestoreThread(_save);
|
||||||
|
|
||||||
|
|
||||||
throw UserInterruptException("User-defined policy is "
|
throw UserInterruptException(_("User-defined policy is "
|
||||||
"taking too long to terminate.");
|
"taking too long to terminate."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while(still_locked);
|
while(still_locked);
|
||||||
|
@ -234,3 +211,36 @@ PythonCPUPolicy::wait_unlock() const throw(UserInterruptException)
|
||||||
} */
|
} */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string
|
||||||
|
PythonCPUPolicy::get_exception_information()
|
||||||
|
{
|
||||||
|
if(PyErr_Occurred() == NULL)
|
||||||
|
return _("no error");
|
||||||
|
|
||||||
|
PyObject* pType = NULL;
|
||||||
|
PyObject* pValue = NULL;
|
||||||
|
PyObject* pTraceback = NULL;
|
||||||
|
|
||||||
|
PyErr_Fetch(&pType, &pValue, &pTraceback);
|
||||||
|
|
||||||
|
string msg;
|
||||||
|
|
||||||
|
if(pValue != NULL)
|
||||||
|
{
|
||||||
|
PyObject* pValueStr = PyObject_Str(pValue);
|
||||||
|
|
||||||
|
msg = PyString_AsString(pValueStr);
|
||||||
|
|
||||||
|
Py_DECREF(pValueStr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
msg = string(_("no available information for this error"));
|
||||||
|
|
||||||
|
if(pType != NULL) Py_DECREF(pType);
|
||||||
|
if(pValue != NULL) Py_DECREF(pValue);
|
||||||
|
if(pTraceback != NULL) Py_DECREF(pTraceback);
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,7 @@ namespace sgpem
|
||||||
PythonCPUPolicy& operator=(const PythonCPUPolicy&);
|
PythonCPUPolicy& operator=(const PythonCPUPolicy&);
|
||||||
|
|
||||||
void wait_unlock() const throw(UserInterruptException);
|
void wait_unlock() const throw(UserInterruptException);
|
||||||
|
static std::string get_exception_information();
|
||||||
|
|
||||||
PyObject* _upolicy_dict;
|
PyObject* _upolicy_dict;
|
||||||
PyObject* _adapter;
|
PyObject* _adapter;
|
||||||
|
|
|
@ -141,7 +141,7 @@ PythonCPUPolicyManager::collect_policies()
|
||||||
}
|
}
|
||||||
catch(MalformedPolicyException e)
|
catch(MalformedPolicyException e)
|
||||||
{
|
{
|
||||||
std::cerr << e.what() << endl;
|
std::cerr << "POLICY LOAD ERROR: " << e.what() << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue