This repository was archived by the owner on Jul 22, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,8 @@ public class Runtime
111111 /// <summary>
112112 /// Initialize the runtime...
113113 /// </summary>
114+ /// <remarks>When calling this method after a soft shutdown or a domain reload,
115+ /// this method acquires and releases the GIL. </remarks>
114116 internal static void Initialize ( bool initSigs = false , ShutdownMode mode = ShutdownMode . Default )
115117 {
116118 if ( _isInitialized )
@@ -149,7 +151,8 @@ internal static void Initialize(bool initSigs = false, ShutdownMode mode = Shutd
149151 }
150152 else
151153 {
152- PyEval_InitThreads ( ) ;
154+ // When initializing more than once (like on soft shutdown and domain
155+ // reload), the GIL might not be acquired by the current thread.
153156 state = PyGILState_Ensure ( ) ;
154157 MainManagedThreadId = Thread . CurrentThread . ManagedThreadId ;
155158 }
@@ -366,6 +369,8 @@ internal static void Shutdown(ShutdownMode mode)
366369 // Some clr runtime didn't implement GC.WaitForFullGCComplete yet.
367370 }
368371 PyGILState_Release ( state ) ;
372+ // Then release the GIL for good.
373+ PyEval_SaveThread ( ) ;
369374 }
370375 else
371376 {
You can’t perform that action at this time.
0 commit comments