I have a class in Python that has resources (such as sockets). I would like to use the class in MATLAB. It is important for me to ensure that the python object will continue to hold his resources. To test how MATLAB will handle this, I created the following class in Python:
class Klaus:
def __init__(self, id):
self.id = id
print "klaus::ctor::id={}".format(self.id)
def __del__(self):
print "klaus::dtor::id={}".format(self.id)
And here is my MATLAB code:
klaus = py.klaus.Klaus(42);
for i = 1:5
disp("klaus says " + klaus.id);
end
delete(klaus);
MATLAB output seems to be in a very unclear order:
klaus::ctor::id=42.0
klaus::dtor::id=42.0
klaus says 42
klaus says 42
klaus says 42
klaus says 42
klaus says 42
klaus::dtor::id=42.0
I excepted that the ctor will be first, following by "klaus says" and the dtor will be in the end. A simple test written in python produces the excepted behavior. But I don't understand why the order is different in MATLAB.
edit: I failed at copy-pasting