!49930 Add Python env check before release GIL

Merge pull request !49930 from caifubi/master-pynative-gil-bugfix
This commit is contained in:
i-robot 2023-03-08 01:15:37 +00:00 committed by Gitee
commit ff8a2d16c6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 1 additions and 1 deletions

View File

@ -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<py::gil_scoped_release>();
}
}