Debugger: way to add some "clean-up" code to be executed before stopping/detaching?

Hi!  I'm trying to debug code that opens up a database connection and, for now, frequently raises an exception before getting to the code that closes the connection.  Thus, when I restart the code, I can't reconnect, until the connection times out.  I've realized that I can put the code in a try block that catches exceptions and closes the DB before exiting, and I also figured out that if I've broken in the debugger and want to detach, I can dig down to the DB connection object and issue its terminate method, but is there a way I can automate this so that such a disconnect is automatically tried for me whenever I select Stop under the Run menu?  Thanks!
4 comments
Comment actions Permalink
I think this might be something that is currently lacking.  Currently when you stop the debugger it sends SIGKILL.

http://forum.jetbrains.com/thread/PyCharm-2234
https://youtrack.jetbrains.com/issue/PY-13316
0
Comment actions Permalink
Is this a feature request that would be welcomed?
--
David Lawrence Goldsmith (DLG)
Software Engineer
Fishery Resource Analysis and Monitoring Division
Northwest Fisheries Science Center – NOAA
2725 Montlake Blvd E.
Seattle, WA 98112
(206) 302-2420 <%28206%29%20860-3341> (w)
(360) 481-3800 (c)
0
Comment actions Permalink
There's a ticket in the Jetbrain issue tracker:

https://youtrack.jetbrains.com/issue/PY-13316

I suppose you could star the issue and/or comment there. I would also welcome a fix.
0
Comment actions Permalink
Sorry, I should have clicked on the links you provided.  Anyway, I added a comment "+2" (for you and myself) to the Issue.  Thanks for not leaving me hanging. :-)
0

Please sign in to leave a comment.