hi,
I'm using boost::python for calling some python code and when the
exception is thrown I want to get type, value and traceback of it.
The problem is with traceback: I got only *one* frame (the first one)
// this always returns Py_None
tb_frame = PyObject_GetAtt rString(tb_fram e, "f_back");
What I'm doing wrong?
void
Deployer::showE rror() {
// PyErr_Print();
PyObject *exc_type, *exc_value, *exc_traceback, *pystring;
PyErr_Fetch(&ex c_type, &exc_value, &exc_traceback) ;
// type works
pystring = PyObject_Str(ex c_type);
char *type = QString(python: :extract<char*> (pystring));
Py_XDECREF(pyst ring);
// value works
pystring = PyObject_Str(ex c_value);
char *value = QString(python: :extract<char*> (pystring));
Py_XDECREF(pyst ring);
// traceback does't work ;(
PyObject *tb_frame = PyObject_GetAtt rString(exc_tra ceback, "tb_frame") ;
while (tb_frame != Py_None) {
PyObject *f_lineno = PyObject_GetAtt rString(tb_fram e, "f_lineno") ;
int lineno = python::extract <int>(f_lineno) ;
Py_XDECREF(f_li neno);
PyObject *f_code = PyObject_GetAtt rString(tb_fram e, "f_code");
PyObject *co_filename = PyObject_GetAtt rString(f_code,
"co_filenam e");
char *filename = python::extract <char*>(co_file name);
Py_XDECREF(f_co de);
Py_XDECREF(co_f ilename);
PyObject *tmp = tb_frame;
// PyObject_Print( tb_frame, stderr, Py_PRINT_RAW);
// fprintf(stderr, "\n");
tb_frame = PyObject_GetAtt rString(tb_fram e, "f_back");
// PyObject_Print( tb_frame, stderr, Py_PRINT_RAW);
// fprintf(stderr, "\n");
Py_XDECREF(tmp) ;
}
Py_XDECREF(exc_ type);
Py_XDECREF(exc_ value);
Py_XDECREF(exc_ traceback);
}
thanks,
Skink
I'm using boost::python for calling some python code and when the
exception is thrown I want to get type, value and traceback of it.
The problem is with traceback: I got only *one* frame (the first one)
// this always returns Py_None
tb_frame = PyObject_GetAtt rString(tb_fram e, "f_back");
What I'm doing wrong?
void
Deployer::showE rror() {
// PyErr_Print();
PyObject *exc_type, *exc_value, *exc_traceback, *pystring;
PyErr_Fetch(&ex c_type, &exc_value, &exc_traceback) ;
// type works
pystring = PyObject_Str(ex c_type);
char *type = QString(python: :extract<char*> (pystring));
Py_XDECREF(pyst ring);
// value works
pystring = PyObject_Str(ex c_value);
char *value = QString(python: :extract<char*> (pystring));
Py_XDECREF(pyst ring);
// traceback does't work ;(
PyObject *tb_frame = PyObject_GetAtt rString(exc_tra ceback, "tb_frame") ;
while (tb_frame != Py_None) {
PyObject *f_lineno = PyObject_GetAtt rString(tb_fram e, "f_lineno") ;
int lineno = python::extract <int>(f_lineno) ;
Py_XDECREF(f_li neno);
PyObject *f_code = PyObject_GetAtt rString(tb_fram e, "f_code");
PyObject *co_filename = PyObject_GetAtt rString(f_code,
"co_filenam e");
char *filename = python::extract <char*>(co_file name);
Py_XDECREF(f_co de);
Py_XDECREF(co_f ilename);
PyObject *tmp = tb_frame;
// PyObject_Print( tb_frame, stderr, Py_PRINT_RAW);
// fprintf(stderr, "\n");
tb_frame = PyObject_GetAtt rString(tb_fram e, "f_back");
// PyObject_Print( tb_frame, stderr, Py_PRINT_RAW);
// fprintf(stderr, "\n");
Py_XDECREF(tmp) ;
}
Py_XDECREF(exc_ type);
Py_XDECREF(exc_ value);
Py_XDECREF(exc_ traceback);
}
thanks,
Skink