Safely using the C API when Python might shut down

It depends on the situation. If I take the example from A new API for ensuring/releasing thread states - #20 by pitrou, I would return a C++ error reflecting the fact that the IO call failed. It’s quite natural and will allow C++ resources to clean up.

That sounds unlikely, no? If you’re being called synchronously from Python, why would PyGILState_EnsureOrSafelyFail not succeed?

In any case, it’s possible to return an error to the calling Python frame.

2 Likes