File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ internal static void Initialize(bool initSigs = false, ShutdownMode mode = Shutd
125125 }
126126 ShutdownMode = mode ;
127127
128+ IntPtr state = IntPtr . Zero ;
128129 if ( Py_IsInitialized ( ) == 0 )
129130 {
130131 Py_InitializeEx ( initSigs ? 1 : 0 ) ;
@@ -148,7 +149,8 @@ internal static void Initialize(bool initSigs = false, ShutdownMode mode = Shutd
148149 }
149150 else
150151 {
151- PyGILState_Ensure ( ) ;
152+ PyEval_InitThreads ( ) ;
153+ state = PyGILState_Ensure ( ) ;
152154 MainManagedThreadId = Thread . CurrentThread . ManagedThreadId ;
153155 }
1541
E820
56
@@ -193,6 +195,10 @@ internal static void Initialize(bool initSigs = false, ShutdownMode mode = Shutd
193195 }
194196 XDecref ( item ) ;
195197 AssemblyManager . UpdatePath ( ) ;
198+ if ( state != IntPtr . Zero )
199+ {
200+ PyGILState_Release ( state ) ;
201+ }
196202 }
197203
198204 private static void InitPyMembers ( )
@@ -314,7 +320,7 @@ internal static void Shutdown()
314320 }
315321 _isInitialized = false ;
316322
317- PyGILState_Ensure ( ) ;
323+ var state = PyGILState_Ensure ( ) ;
318324
319325 var mode = ShutdownMode ;
320326 if ( mode == ShutdownMode . Soft )
@@ -360,7 +366,7 @@ internal static void Shutdown()
360366 {
361367 // Some clr runtime didn't implement GC.WaitForFullGCComplete yet.
362368 }
363- PyEval_SaveThread ( ) ;
369+ PyGILState_Release ( state ) ;
364370 }
365371 else
366372 {
You can’t perform that action at this time.
0 commit comments