| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b35f441 commit ce8ee90
1 file 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 | |||
| 125 | 125 | } | |
| 126 | 126 | ShutdownMode = mode; | |
| 127 | 127 | ||
| 128 | + IntPtr state = IntPtr.Zero; | ||
| 128 | 129 | if (Py_IsInitialized() == 0) | |
| 129 | 130 | { | |
| 130 | 131 | Py_InitializeEx(initSigs ? 1 : 0); | |
@@ -148,7 +149,8 @@ internal static void Initialize(bool initSigs = false, ShutdownMode mode = Shutd | |||
| 148 | 149 | } | |
| 149 | 150 | else | |
| 150 | 151 | { | |
| 151 | - PyGILState_Ensure(); | ||
| 152 | + PyEval_InitThreads(); | ||
| 153 | + state = PyGILState_Ensure(); | ||
| 152 | 154 | MainManagedThreadId = Thread.CurrentThread.ManagedThreadId; | |
| 153 | 155 | } | |
| 154 | 156 | ||
@@ -193,6 +195,10 @@ internal static void Initialize(bool initSigs = false, ShutdownMode mode = Shutd | |||
| 193 | 195 | } | |
| 194 | 196 | XDecref(item); | |
| 195 | 197 | AssemblyManager.UpdatePath(); | |
| 198 | + if (state != IntPtr.Zero) | ||
| 199 | + { | ||
| 200 | + PyGILState_Release(state); | ||
| 201 | + } | ||
| 196 | 202 | } | |
| 197 | 203 | ||
| 198 | 204 | private static void InitPyMembers() | |
@@ -314,7 +320,7 @@ internal static void Shutdown() | |||
| 314 | 320 | } | |
| 315 | 321 | _isInitialized = false; | |
| 316 | 322 | ||
| 317 | - PyGILState_Ensure(); | ||
| 323 | + var state = PyGILState_Ensure(); | ||
| 318 | 324 | ||
| 319 | 325 | var mode = ShutdownMode; | |
| 320 | 326 | if (mode == ShutdownMode.Soft) | |
@@ -360,7 +366,7 @@ internal static void Shutdown() | |||
| 360 | 366 | { | |
| 361 | 367 | // Some clr runtime didn't implement GC.WaitForFullGCComplete yet. | |
| 362 | 368 | } | |
| 363 | - PyEval_SaveThread(); | ||
| 369 | + PyGILState_Release(state); | ||
| 364 | 370 | } | |
| 365 | 371 | else | |
| 366 | 372 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments