diff --git a/mindspore/ccsrc/pybind_api/gil_scoped_long_running.h b/mindspore/ccsrc/pybind_api/gil_scoped_long_running.h index 9af798005b8..e7b8fdcdb48 100644 --- a/mindspore/ccsrc/pybind_api/gil_scoped_long_running.h +++ b/mindspore/ccsrc/pybind_api/gil_scoped_long_running.h @@ -42,7 +42,7 @@ class GilScopedLongRunningHook : public ScopedLongRunningHook { class GilReleaseWithCheck { public: GilReleaseWithCheck() { - if (PyGILState_Check() != 0) { + if (Py_IsInitialized() != 0 && PyGILState_Check() != 0) { release_ = std::make_unique(); } }