| 232 | explicit OwnedRefNoGIL(PyObject* obj) : OwnedRef(obj) {} |
| 233 | |
| 234 | ~OwnedRefNoGIL() { |
| 235 | // GH-38626: destructor may be called after the Python interpreter is finalized. |
| 236 | if (Py_IsInitialized() && obj() != NULLPTR) { |
| 237 | PyAcquireGIL lock; |
| 238 | reset(); |
| 239 | } |
| 240 | } |
| 241 | }; |
| 242 | |
| 243 | template <template <typename...> typename SmartPtr, typename... Ts> |