diff --git a/mindspore/ccsrc/pybind_api/gil_scoped_long_running.h b/mindspore/ccsrc/pybind_api/gil_scoped_long_running.h index 7b2d259ee76..bb647fb8216 100644 --- a/mindspore/ccsrc/pybind_api/gil_scoped_long_running.h +++ b/mindspore/ccsrc/pybind_api/gil_scoped_long_running.h @@ -28,7 +28,11 @@ namespace py = pybind11; namespace mindspore { class GilScopedLongRunningHook : public ScopedLongRunningHook { public: - void Enter() override { release_ = std::make_unique(); } + void Enter() override { + if (PyGILState_Check() != 0) { + release_ = std::make_unique(); + } + } void Leave() override { release_ = nullptr; } private: