Handle ProcessExit event by lostmsu · Pull Request #1458 · pythonnet/pythonnet

This avoids segfault when CLR (in particular Mono) is unloaded before Python stops.

What does this implement/fix? Explain your changes.

  1. Added a handler to AppDomain.ProcessExit, that fires in the situations like this instead of AppDomain.DomainUnload. This allows Python.NET to remove all slots, that are implemented in C#.
  2. When initialized as extension (e.g. Python hosts CLR), release GIL acquired during shutdown so that Python finalization can resume.

Does this close any currently open issues?

This is (at least one of) the reason of CI test crashes in #1134