Skip to content

Commit a49f3a8

Browse files
authored
Take GIL when checking if error occurred on shutdown (#1836)
1 parent 70e2e0a commit a49f3a8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/runtime/PythonEngine.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,17 @@ public static void Shutdown()
355355
{
356356
return;
357357
}
358-
if (Exceptions.ErrorOccurred())
358+
359+
using (Py.GIL())
359360
{
360-
throw new InvalidOperationException(
361-
"Python error indicator is set",
362-
innerException: PythonException.PeekCurrentOrNull(out _));
361+
if (Exceptions.ErrorOccurred())
362+
{
363+
throw new InvalidOperationException(
364+
"Python error indicator is set",
365+
innerException: PythonException.PeekCurrentOrNull(out _));
366+
}
363367
}
368+
364369
// If the shutdown handlers trigger a domain unload,
365370
// don't call shutdown again.
366371
AppDomain.CurrentDomain.DomainUnload -= OnDomainUnload;

0 commit comments

Comments
 (0)