Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8d61215

Browse files
committed
when process is exiting, there's no need to save live .NET objects as they won't be resurrected
1 parent ec8b69f commit 8d61215

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/runtime/pythonengine.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ static void OnDomainUnload(object _, EventArgs __)
296296

297297
static void OnProcessExit(object _, EventArgs __)
298298
{
299+
Runtime.ProcessIsTerminating = true;
299300
Shutdown();
300301
}
301302

src/runtime/runtime.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ internal static int GetRun()
9292
}
9393

9494
internal static bool HostedInPython;
95+
internal static bool ProcessIsTerminating;
9596

9697
/// Initialize the runtime...
9798
/// </summary>
@@ -254,7 +255,7 @@ internal static void Shutdown()
254255

255256
var state = PyGILState_Ensure();
256257

257-
if (!HostedInPython)
258+
if (!HostedInPython && !ProcessIsTerminating)
258259
{
259260
// avoid saving dead objects
260261
TryCollectingGarbage(runs: 3);

0 commit comments

Comments
 (0)