Skip to content

Commit 5eccd45

Browse files
committed
Use Py.GIL directly, now that it doesn't try to init anymore
1 parent bbfa252 commit 5eccd45

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

src/runtime/Loader.cs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,8 @@ public unsafe static int Initialize(IntPtr data, int size)
2323
PythonDLL = null;
2424
}
2525

26-
var gs = PyGILState_Ensure();
27-
28-
try
29-
{
30-
// Console.WriteLine("Startup thread");
31-
PythonEngine.InitExt();
32-
// Console.WriteLine("Startup finished");
33-
}
34-
finally
35-
{
36-
PyGILState_Release(gs);
37-
}
26+
using var _ = Py.GIL();
27+
PythonEngine.InitExt();
3828
}
3929
catch (Exception exc)
4030
{
@@ -55,15 +45,8 @@ public unsafe static int Shutdown(IntPtr data, int size)
5545

5646
if (command == "full_shutdown")
5747
{
58-
var gs = PyGILState_Ensure();
59-
try
60-
{
61-
PythonEngine.Shutdown();
62-
}
63-
finally
64-
{
65-
PyGILState_Release(gs);
66-
}
48+
using var _ = Py.GIL();
49+
PythonEngine.Shutdown();
6750
}
6851
}
6952
catch (Exception exc)

0 commit comments

Comments
 (0)