From 071262047f35291c722fef14de0c240d1c812323 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Mon, 27 Jun 2022 09:29:41 +0000 Subject: [PATCH] Take GIL when checking if error occurred on shutdown --- src/runtime/PythonEngine.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/runtime/PythonEngine.cs b/src/runtime/PythonEngine.cs index f184ebe88..6e9c4d1f1 100644 --- a/src/runtime/PythonEngine.cs +++ b/src/runtime/PythonEngine.cs @@ -355,12 +355,17 @@ public static void Shutdown() { return; } - if (Exceptions.ErrorOccurred()) + + using (Py.GIL()) { - throw new InvalidOperationException( - "Python error indicator is set", - innerException: PythonException.PeekCurrentOrNull(out _)); + if (Exceptions.ErrorOccurred()) + { + throw new InvalidOperationException( + "Python error indicator is set", + innerException: PythonException.PeekCurrentOrNull(out _)); + } } + // If the shutdown handlers trigger a domain unload, // don't call shutdown again. AppDomain.CurrentDomain.DomainUnload -= OnDomainUnload;