[Tutor] ensuring a __del__ method happens
Daniel Yoo
dyoo@hkn.eecs.berkeley.edu
Mon, 26 Mar 2001 18:05:41 -0800 (PST)
On Mon, 26 Mar 2001, Sean 'Shaleh' Perry wrote:
> SO, I have a class Foo which maps to a directory. When you create
> Foo, it makes a directory of the form /tmp/foo-pid. I would like for
> this dir to be removed when the object leaves scope (i.e. when __del__
> is called). However this does not seem to work if the object exists
> when python exists. Any ideas?
It might be better to have a close() method in your Foo that explicitly
removes the temporary directory. The semantics would be similar to how
files close() themselves: they call close() through __del__, but they also
allow the user to call close() directly to give finer control.
If there aren't any more references to your Foo object, it should call
__del__. Can you double check to see if something else has a link to your
Foo?