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
[Actual behavior:]
But running with IronPython, there's nothing output.
This blocks #938. FileIO, TextIOWrapper etc classes have finalizer (defined in their base class _IOBase) calling close(). But the finalizer is never called.
__del__ is called by dotnet finalizer. When the IronPython process ends and there's some objects in the finalizer queue, these finalizers won't be invoked.
So adding the following C# code at the end of PythonContext.Shutdown(),
GC.Collect();GC.WaitForPendingFinalizers();
we could get partial output
Foo 3
Foo 2
Foo 1
The missing of Foo 4 from the output, means that the global variable is still referenced
I have run into a similar issue when developing the buffer protocol support for memoryview. Unfortunately, it seems that running gc.collect() is the only way to make it work, due to a different operational principle between the .NET and CPython garbage collectors.
Perhaps we could always do collect and wait for pending finalizers when the IronPython process closes. It is less clear what to do in embedded scenarios.
Activity
jameslan commentedon Oct 15, 2020
__del__is called by dotnet finalizer. When the IronPython process ends and there's some objects in the finalizer queue, these finalizers won't be invoked.So adding the following C# code at the end of
PythonContext.Shutdown(),we could get partial output
The missing of
Foo 4from the output, means that the global variable is still referencedBCSharp commentedon Oct 15, 2020
I have run into a similar issue when developing the buffer protocol support for
memoryview. Unfortunately, it seems that runninggc.collect()is the only way to make it work, due to a different operational principle between the .NET and CPython garbage collectors.Perhaps we could always do collect and wait for pending finalizers when the IronPython process closes. It is less clear what to do in embedded scenarios.
slozier commentedon Oct 15, 2020
Interestingly with .NET Framework I get all 4 outputs but with .NET Core only 3 (assuming I add GC collect to
PythonContext.Shutdown)?