diff --git a/src/runtime/PythonEngine.cs b/src/runtime/PythonEngine.cs index f184ebe88..5d1069db0 100644 --- a/src/runtime/PythonEngine.cs +++ b/src/runtime/PythonEngine.cs @@ -355,12 +355,26 @@ public static void Shutdown() { return; } + + // If we're embedded, we need to take the GIL, if it wasn't already + // taken, as we may get called from the DomainUnload handler. + var pyGILState = PyGILState.PyGILState_UNLOCKED; + if (!Runtime.HostedInPython) + { + pyGILState = Runtime.PyGILState_Ensure(); + } + if (Exceptions.ErrorOccurred()) { throw new InvalidOperationException( "Python error indicator is set", innerException: PythonException.PeekCurrentOrNull(out _)); } + + if (!Runtime.HostedInPython) + { + Runtime.PyGILState_Release(pyGILState); + } // If the shutdown handlers trigger a domain unload, // don't call shutdown again. AppDomain.CurrentDomain.DomainUnload -= OnDomainUnload; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy