diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-07 20:19:23 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-07 20:19:23 +0000 |
commit | 6b7a8a38f609117572820711638508a23ad57850 (patch) | |
tree | cfd15ced8363fa5163cbf874ec01178254169fbf /sca-cpp/trunk/modules/python/eval.hpp | |
parent | 9f67144615b018828226949701a6935336cbfc43 (diff) |
Support HTTPD graceful restarts for non-stop operation. Simplified Python and Java error capture and recovery.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@907470 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/python/eval.hpp')
-rw-r--r-- | sca-cpp/trunk/modules/python/eval.hpp | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/sca-cpp/trunk/modules/python/eval.hpp b/sca-cpp/trunk/modules/python/eval.hpp index 09c2cba92d..5231b0ef60 100644 --- a/sca-cpp/trunk/modules/python/eval.hpp +++ b/sca-cpp/trunk/modules/python/eval.hpp @@ -29,33 +29,52 @@ #include "list.hpp" #include "value.hpp" -#include "io.hpp" namespace tuscany { namespace python { /** - * Initialize the Python runtime. + * Represent a Python runtime. */ class PythonRuntime { public: - PythonRuntime() : owner(true) { + PythonRuntime() { + if (Py_IsInitialized()) + return; Py_InitializeEx(0); - setupIO(); - } - - PythonRuntime(unused const PythonRuntime& r) : owner(false) { } +}; - ~PythonRuntime() { - if (!owner) - return; - //Py_Finalize(); +/** + * Return the last python error. + */ +const string lastError() { + if(PyErr_Occurred()) { + PyObject* type; + PyObject* val; + PyObject* trace; + PyErr_Fetch(&type, &val, &trace); + if (type != NULL && val != NULL) { + PyObject* stype = PyObject_Str(type); + PyObject* sval = PyObject_Str(val); + string msg = string() + PyString_AsString(stype) + " : " + PyString_AsString(sval); + Py_DECREF(stype); + Py_DECREF(sval); + Py_DECREF(type); + Py_DECREF(val); + Py_XDECREF(trace); + PyErr_Print(); + return msg; + } + PyErr_Print(); + Py_XDECREF(type); + Py_XDECREF(val); + Py_XDECREF(trace); + PyErr_Print(); + return "Unknown Python error"; } - -private: - const bool owner; -}; + return ""; +} /** * Declare conversion functions. @@ -222,8 +241,10 @@ const failable<value> evalScript(const value& expr, PyObject* script) { // The start, stop, and restart functions are optional const value fn = car<value>(expr); - if (fn == "start" || fn == "stop" || fn == "restart") + if (fn == "start" || fn == "stop" || fn == "restart") { + PyErr_Clear(); return value(false); + } return mkfailure<value>(string("Couldn't find function: ") + car<value>(expr) + " : " + lastError()); } |