* @brief Get the string representation of the current Python stack * * Use Python’s traceback module to obtain the current stack information and * convert it into a string representation for return. * * @return String representation of the current Python stack */
| 383 | * @return String representation of the current Python stack |
| 384 | */ |
| 385 | std::string GetPythonStack() { |
| 386 | pybind11::gil_scoped_acquire gil; |
| 387 | PyObject* mod = PyImport_ImportModule("traceback"); |
| 388 | PyObject* traceback_list = PyObject_CallMethod(mod, "format_stack", ""); |
| 389 | std::string str = ""; |
| 390 | for (Py_ssize_t i = 0; i < PyList_Size(traceback_list); i++) { |
| 391 | PyObject* line = PyList_GetItem(traceback_list, i); |
| 392 | str += py::str(PyUnicode_AsUTF8(line)); |
| 393 | } |
| 394 | return str; |
| 395 | } |
| 396 | void SetPythonStack() { |
| 397 | if (FLAGS_check_nan_inf && FLAGS_check_nan_inf_level == 0) { |
| 398 | VLOG(4) << "this is SetPythonStack"; |
no test coverage detected