Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Handle ProcessExit event#1458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lostmsu merged 1 commit intopythonnet:masterfromlosttech:bugs/PyCrashOnExit
May 29, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletionssrc/runtime/pythonengine.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -192,6 +192,7 @@ public static void Initialize(IEnumerable<string> args, bool setSysArgv = true,

// Make sure we clean up properly on app domain unload.
AppDomain.CurrentDomain.DomainUnload += OnDomainUnload;
AppDomain.CurrentDomain.ProcessExit += OnProcessExit;

// The global scope gets used implicitly quite early on, remember
// to clear it out when we shut down.
Expand DownExpand Up@@ -249,6 +250,11 @@ static void OnDomainUnload(object _, EventArgs __)
Shutdown();
}

static void OnProcessExit(object _, EventArgs __)
{
Shutdown();
}

/// <summary>
/// A helper to perform initialization from the context of an active
/// CPython interpreter process - this bootstraps the managed runtime
Expand DownExpand Up@@ -319,6 +325,7 @@ public static void Shutdown(ShutdownMode mode)
// If the shutdown handlers trigger a domain unload,
// don't call shutdown again.
AppDomain.CurrentDomain.DomainUnload -= OnDomainUnload;
AppDomain.CurrentDomain.ProcessExit -= OnProcessExit;

PyScopeManager.Global.Clear();
ExecuteShutdownHandlers();
Expand Down
4 changes: 4 additions & 0 deletionssrc/runtime/runtime.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -393,6 +393,10 @@ internal static void Shutdown(ShutdownMode mode)
{
Py_Finalize();
}
else
{
PyGILState_Release(state);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This change seems unrelated, why did you add this?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Without thisPy_Finalize called when Python finally shuts down hangs because it can't acquire GIL.

}
}
}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp