diff --git a/paddle/fluid/pybind/op_function.h b/paddle/fluid/pybind/op_function.h index 1cfef605bcd0be73ba5172be266ed2ffe1497377..e0886ac144ab139f56ac1e1878a64e1f94812047 100644 --- a/paddle/fluid/pybind/op_function.h +++ b/paddle/fluid/pybind/op_function.h @@ -984,12 +984,11 @@ void InitOpsAttrTypeMap() { } } -PyObject* EOFExceptionException = - PyErr_NewException("paddle.EOFException", PyExc_Exception, NULL); -PyObject* EnforceNotMetException = - PyErr_NewException("paddle.EnforceNotMet", PyExc_Exception, NULL); - void ThrowExceptionToPython(std::exception_ptr p) { + static PyObject* EOFExceptionException = + PyErr_NewException("paddle.EOFException", PyExc_Exception, NULL); + static PyObject* EnforceNotMetException = + PyErr_NewException("paddle.EnforceNotMet", PyExc_Exception, NULL); try { if (p) std::rethrow_exception(p); } catch (const platform::EOFException& e) {