I am working on some code that connects to an sqlite database. In the process of debugging said code, I am running into problems where I have hanging open connections to the database because some error prevented the execution of the close commands. Because db and c are defined within a function, I can't then find and close those objects from the command line. They are like orphaned connections or something, but in any case they prevent me from doing anything else with the database until I close and reopen my interactive console. Here's what it looks like:
def something()
db=sqlite3.connect('mydatabase')
c=db.cursor()
somecode
lots of different things happening in here
this may have errors
thus stopping execution
db.commit()
c.close()
db.close()
I have tried a try/except clause with the final closing operations in a "finally" block, but that prevents exceptions from being raised back to the interactive output when I'm debugging, and things fail "silently" (maybe I'm not doing that part right?). Is there a better way to do this?