Calling del
on a name is something you prettymuch never should do. Calling del
does not guarantee anything useful about what will happen to the underlying object. You should never depend on a __del__
method for something you need to happen.
del
only gets rid of one reference to an object, which can be confusing when you may have made more without thinking. Therefore, del
is useful for cleaning up a namespace, not for controlling the lifetime of objects, and it's not even great for that—the proper way to control a name's lifetime is to put it in a function and have it go out of scope or put it in a with block.
You need to equip BigHash
with the ability to release the lock explicitly, with an release
or unlock
or close
method. If you want to use this with a context manager (with
), you can define __exit__
, which will get called at a predictable, useful time.