You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exception thrown when initializing Python .NET after a domain unload #714
Pythonnet version: latest master commit as of 2018-08-09 (fb84cd2 )
Python version:
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
Operating System:
Windows 10
In the context of running in Unity, but also reproducible in a simple standalone app made from scratch
Details
Unity, whenever a C# script is changed, the AppDomain in which the Assemblies are loaded gets unloaded. Then, Unity creates a fresh AppDomain, recompiles the C# assemblies and loads them again.
The Python.Runtime assembly gets unloaded, but the Python interpreter survives (it is a native library). This results in an inconsistent state between the Python .NET Engine/Runtime classes (which are not initialized) and the Python interpreter (which is initialized).
An exception is raised when Python .NET accesses the interpreter (System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.)
I will attach my standalone application which reproduces this crash along with the repro steps. (either ere or on the pull request if I cannot attach here)
(Note: with the upcoming fix, the application will still raise an exception, but on the second domain unload - a bit further. A fix for this second crash is under review)
Python crashed because pythonnet's function pointers just leak in Python, you can just reset the Python GC avoid that, although it would make more memory leaks in unity editor.
By the way, I'm working on a new binding mode for Python call that supported IL2CPP and with more higher performance, this pythonnet will a part of my unity package. https://github.com/amos402/pythonnet/tree/fast-call
By the way, I'm working on a new binding mode for Python call that supported IL2CPP and with more higher performance, this pythonnet will a part of my unity package. https://github.com/amos402/pythonnet/tree/fast-call
@amos402 did you ever make any headway with the new binding mode that enables IL2CPP support? If not, any chance I could see what you accomplished at the time?
I'm working on a unity project that compiles to IL2CPP on iOS and Android. Since iOS does not have Mono support this is not an option otherwise.
Activity
lassond commentedon Aug 9, 2018
hotReloadCrashRepro.zip
(Note: with the upcoming fix, the application will still raise an exception, but on the second domain unload - a bit further. A fix for this second crash is under review)
amos402 commentedon Sep 6, 2018
Python crashed because pythonnet's function pointers just leak in Python, you can just reset the Python GC avoid that, although it would make more memory leaks in unity editor.
You can modify Python like below:
amos402/cpython@3fb76b5
By the way, I'm working on a new binding mode for Python call that supported IL2CPP and with more higher performance, this pythonnet will a part of my unity package.
https://github.com/amos402/pythonnet/tree/fast-call
benoithudson commentedon Oct 23, 2018
This is fixed and the test case integrated in #752. But I don't have permissions to close the bug.
filmor commentedon Oct 23, 2018
But I do, thanks again :)
dyeo commentedon Jul 7, 2021
@amos402 did you ever make any headway with the new binding mode that enables IL2CPP support? If not, any chance I could see what you accomplished at the time?
I'm working on a unity project that compiles to IL2CPP on iOS and Android. Since iOS does not have Mono support this is not an option otherwise.