8000 Add a parameter to specify the shutdown mode. · pythonnet/pythonnet@4c4bcb0 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 4c4bcb0

Browse files
committed
Add a parameter to specify the shutdown mode.
Addresses comment: #958
1 parent ce8ee90 commit 4c4bcb0

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/runtime/pythonengine.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ public static void Initialize(IEnumerable<string> args, bool setSysArgv = true,
189189
// Make sure we clean up properly on app domain unload.
190190
AppDomain.CurrentDomain.DomainUnload += OnDomainUnload;
191191

192-
// Remember to shut down the runtime.
193-
AddShutdownHandler(Runtime.Shutdown);
194-
195192
// The global scope gets used implicitly quite early on, remember
196193
// to clear it out when we shut down.
197194
AddShutdownHandler(PyScopeManager.Global.Clear);
@@ -318,7 +315,8 @@ public static IntPtr InitExt()
318315
/// Python runtime can no longer be used in the current process
319316
/// after calling the Shutdown method.
320317
/// </remarks>
321-
public static void Shutdown()
318+
/// <param name="mode">The ShutdownMode to use when shutting down the Runtime</param>
319+
public static void Shutdown(ShutdownMode mode)
322320
{
323321
if (!initialized)
324322
{
@@ -330,11 +328,26 @@ public static void Shutdown()
330328

331329
PyScopeManager.Global.Clear();
332330
ExecuteShutdownHandlers();
331+
// Remember to shut down the runtime.
332+
Runtime.Shutdown(mode);
333333
PyObjectConversions.Reset();
334334

335335
initialized = false;
336336
}
337337

338+
/// <summary>
339+
/// Shutdown Method
340+
/// </summary>
341+
/// <remarks>
342+
/// Shutdown and release resources held by the Python runtime. The
343+
/// Python runtime can no longer be used in the current process
344+
/// after calling the Shutdown method.
345+
/// </remarks>
346+
public static void Shutdown()
347+
{
348+
Shutdown(Runtime.ShutdownMode);
349+
}
350+
338351
/// <summary>
339352
/// Called when the engine is shut down.
340353
///

src/runtime/runtime.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ private static IntPtr Get_PyObject_NextNotImplemented()
312312
return iternext;
313313
}
314314

315-
internal static void Shutdown()
315+
internal static void Shutdown(ShutdownMode mode)
316316
{
317317
if (Py_IsInitialized() == 0 || !_isInitialized)
318318
{
@@ -322,7 +322,6 @@ internal static void Shutdown()
322322

323323
var state = PyGILState_Ensure();
324324

325-
var mode = ShutdownMode;
326325
if (mode == ShutdownMode.Soft)
327326
{
328327
RunExitFuncs();
@@ -375,6 +374,12 @@ internal static void Shutdown()
375374
}
376375
}
377376

377+
internal static void Shutdown()
378+
{
379+
var mode = ShutdownMode;
380+
Shutdown(mode);
381+
}
382+
378383
internal static ShutdownMode GetDefaultShutdownMode()
379384
{
380385
string modeEvn = Environment.GetEnvironmentVariable("PYTHONNET_SHUTDOWN_MODE");

0 commit comments

Comments
 (0)
0