17 UINFO(
"Initialize python interpreter");
18 guard_ =
new pybind11::scoped_interpreter();
19 pybind11::module::import(
"threading");
20 release_ =
new pybind11::gil_scoped_release();
25 UINFO(
"Finalize python interpreter");
39 PyErr_NormalizeException(&
type, &
value, &traceback);
42 fcn +=
"def get_pretty_traceback(exc_type, exc_value, exc_tb):\n";
43 fcn +=
" import sys, traceback\n";
44 fcn +=
" lines = []\n";
45 fcn +=
" lines = traceback.format_exception(exc_type, exc_value, exc_tb)\n";
46 fcn +=
" output = '\\n'.join(lines)\n";
47 fcn +=
" return output\n";
49 PyRun_SimpleString(fcn.c_str());
50 PyObject*
mod = PyImport_ImportModule(
"__main__");
52 PyObject* method = PyObject_GetAttrString(
mod,
"get_pretty_traceback");
54 PyObject* outStr = PyObject_CallObject(method, Py_BuildValue(
"OOO",
type,
value, traceback));