title: How to use __del__ in a reliable way?
body: <p>I have learned that python <a href="http://docs.python.org/reference/datamodel.html#object.__del__" rel="nofollow noreferrer">does</a> <a href="https://stackoverflow.com/questions/1481488/how-to-call-the-del-method">not</a> <a href="https://stackoverflow.com/questions/4199653/in-python-2-x-should-i-call-object-del">guarantee</a> that <code>__del__</code> is called whenever an object is deleted.
  In other words, <code>del x</code> <strong>does not</strong> necessarily <strong>invoke</strong> its destructor <code>x.__del__()</code>.</p>
  
  <p>If I want to ensure proper object cleanup, I should use a <a href="http://docs.python.org/release/2.7.2/reference/datamodel.html#context-managers" rel="nofollow noreferrer">context manager</a> (in a <code>with</code> statement).</p>
  
  <p>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)</p>
  
  <p>So I need a an alternative solution, and hence my question: are there best practices that would help me to use <code>__del__</code> reliably? I am thinking in the direction of <em>"if python provides such functionality, there must be a way it can be efficiently used (I'm just to stupid to figure out how)",,,</em></p>
  
  <p>Or I am just being naive, should forget about <code>__del__</code> and move on to a completely different approach?</p>