Say I have some class that manages a database connection. The user is supposed to call close()
on instances of this class so that the db connection is terminated cleanly.
Is there any way in python to get this object to call close()
if the interpreter is closed or the object is otherwise picked up by the garbage collector?
Edit: This question assumes the user of the object failed to instantiate it within a with
block, either because he forgot or isn't concerned about closing connections.