python - How to ensure sqlite db connections get closed during debugging? -
I'm working on some code that connects to a SQLite database, in the debugging process, the code said, in the problems I am running where I have blocked the open connection to the database because some errors prevented from implementing closed orders. Because DB and C are defined within a function, I can not find those objects from the command line and can not stop they are like orphaned connections or some things, but as long as I can not close my interactive console And in any case, they prevent me from doing anything else from the database. Here is something that looks like:
def some () db = sqlite3.connect ('mydatabase') C = db.cursor () Here are some different things These errors may occur, thus preventing the execution of db.commit () c.close () db.close () The last closing work in the "end" block Has attempted to leave an attempt / clearance with, but when I debugging it prevents exceptions from getting back into the interactive output, and things "quietly" (maybe I'm not correcting that part) Can i fail Is there a better way to do this?
"post-text" itemprop = "text"> Normally it is good to experiment with ...
sqlite.connect (.. .) With db: db.cursor () with c: ... with the statement statement that when closed () Will be called on an object or when the statement ends or an exception is raised and even when the return or yield is called from within. Read more here:
Comments
Post a Comment