!24562 Enable MD cleanup at module exit

Merge pull request !24562 from luoyang/cleanup
This commit is contained in:
i-robot 2021-10-11 08:09:30 +00:00 committed by Gitee
commit ebf2cc4041
1 changed files with 6 additions and 7 deletions

View File

@ -302,16 +302,15 @@ PYBIND11_MODULE(_c_expression, m) {
.def("reset_algo_parameters", &CostModelContext::ResetAlgoParameters, "Reset the AlgoParameters.");
(void)py::module::import("atexit").attr("register")(py::cpp_function{[&]() -> void {
#ifdef ENABLE_MINDDATA
MS_LOG(INFO) << "Start releasing dataset handles...";
py::module iterators = py::module::import("mindspore.dataset.engine.iterators");
(void)iterators.attr("_cleanup")();
MS_LOG(INFO) << "End release dataset handles.";
#endif
// only in case that c++ calling python interface, ClearResAtexit should be called.
if (mindspore::parse::python_adapter::IsPythonEnv()) {
mindspore::pipeline::ClearResAtexit();
#ifdef ENABLE_MINDDATA
MS_LOG(INFO) << "Start releasing dataset handles...";
py::module iterators = py::module::import("mindspore.dataset.engine.iterators");
(void)iterators.attr("_cleanup")();
MS_LOG(INFO) << "End release dataset handles.";
#endif
}
}});