Only try to acquire the GIL if the Python interpreter is actually
initialized, otherwise there'll be a segfault.
* Acquire the GIL, otherwise Py_Finalize() might have issues.
* Ignore the return value, we don't need it here.
*/
- (void)PyGILState_Ensure();
+ if (Py_IsInitialized())
+ (void)PyGILState_Ensure();
/* Py_Finalize() returns void, any finalization errors are ignored. */
Py_Finalize();