Add Python env check for gil

This commit is contained in:
caifubi 2023-03-07 19:26:03 +08:00
parent e2ac12b1ad
commit ffb5c55b6c
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>();
}
}