title: Python how to ensure that __del__() method of an object is called before the module dies?
body: <p>Earlier today I asked <a href="https://stackoverflow.com/questions/14984136/python-2-7-possible-bug-imported-modules-disappears">this</a> question about the <code>__del__()</code> method of an object which uses an imported module. The problem was that <code>__del__()</code> wants to make use of the module <code>os</code>, but sometimes (not always) the module has already been deleted. I was told that when a Python program terminates, the order in which objects and modules are deleted can be random, and is undefined. However, for my application, I really need to make sure that an object (instance of a class I created) gets deleted before the module (in which the object is instantiated) gets deleted. Is there a way of doing this?</p>