| 282 | } |
| 283 | |
| 284 | std::string consumePythonError() { |
| 285 | if (!PyErr_Occurred()) { |
| 286 | return "unknown Python error"; |
| 287 | } |
| 288 | |
| 289 | PyObject* type = nullptr; |
| 290 | PyObject* value = nullptr; |
| 291 | PyObject* traceback = nullptr; |
| 292 | PyErr_Fetch(&type, &value, &traceback); |
| 293 | PyErr_NormalizeException(&type, &value, &traceback); |
| 294 | |
| 295 | std::string message = "unknown Python error"; |
| 296 | if (value) { |
| 297 | PyObject* as_str = PyObject_Str(value); |
| 298 | if (as_str) { |
| 299 | if (const char* utf8 = PyUnicode_AsUTF8(as_str)) { |
| 300 | message = utf8; |
| 301 | } |
| 302 | Py_DECREF(as_str); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | Py_XDECREF(type); |
| 307 | Py_XDECREF(value); |
| 308 | Py_XDECREF(traceback); |
| 309 | return message; |
| 310 | } |
| 311 | |
| 312 | PythonTensorResult runPythonTensorSnippet(const std::string& script) { |
| 313 | const lfs::python::GilAcquire gil; |
no outgoing calls
no test coverage detected