I have learned that python does not guarantee that __del__
is called whenever an object is deleted.
In other words, del x
does not necessarily invoke its destructor x.__del__()
.
If I want to ensure proper object cleanup, I should use a context manager (in a with
statement).
I know it's stupid, but for a couple of reasons (please don't ask why) I am tied to a system with Python 2.4; therefore context managers are out of question (they were introduced in Python 2.5)
So I need a an alternative solution, and hence my question: are there best practices that would help me to use __del__
reliably? I am thinking in the direction of "if python provides such functionality, there must be a way it can be efficiently used (I'm just to stupid to figure out how)",,,
Or I am just being naive, should forget about __del__
and move on to a completely different approach?