Recently, I developed dynamic object in C# ( a small library of sort) that I can link to my python application (excuse my nomenclature if it's not right). I have some IDisposable object that opens the file in the constructor and then closes it in Dispose()
method. The file needs to stay open throughout the object's life.
I would expect Dispose()
method would be call automatically after last live reference but instead I have to call it explicitly.
- Python 3.7.3
- Ubuntu 18.04.2
- pythonnet 2.4.0
- mono 5.18.1.28
import clr
clr.AddReference("MyLibrary")
from MyLibrary import DynamicObject
and then use it further in my code:
def foo():
my_obj = DynamicObject()
...
my_obj().Dispose() # have to call it here
return
Moreover, the finalizer is not called either. Is there a way to make use of either finalizer or Dispose()
method and not call them explicitly or garbage collector from CLR has no idea what is going on in my python script? How python communicates through python.net?
Thank you :- )