Skip to content

Uni-50101-Fixing_the_domain_reload_crash_on_second_init #697

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all 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
* Now calling PythonEngine.Shutdown on app domain unload
  • Loading branch information
David Lassonde committed Jul 4, 2018
commit 7736001550dad09fdf9857a7948dbaf25ef7b0bd
16 changes: 16 additions & 0 deletions src/runtime/pythonengine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ public static void Initialize(bool setSysArgv = true)
Initialize(Enumerable.Empty<string>(), setSysArgv: setSysArgv);
}

/// <summary>
/// On Domain Unload Event Handler
/// </summary>
/// <remarks>
/// Performs necessary tasks (shutdown) when the current app domain
/// gets unloaded, leaving the engine, the runtime and the Python
/// interpreter in consistent states
/// </remarks>
private static void OnDomainUnload(object sender, EventArgs e)
{
Shutdown();
}

/// <summary>
/// Initialize Method
/// </summary>
Expand All @@ -158,6 +171,9 @@ public static void Initialize(IEnumerable<string> args, bool setSysArgv = true)
{
if (!initialized)
{
// Make sure we shut down properly on app domain reload
System.AppDomain.CurrentDomain.DomainUnload += new EventHandler(OnDomainUnload);

// Creating the delegateManager MUST happen before Runtime.Initialize
// is called. If it happens afterwards, DelegateManager's CodeGenerator
// throws an exception in its ctor. This exception is eaten somehow
Expand Down