0
a part that executes only at the end
I have a part of code that i want it to be executed only when i STOP the program. For example closing a connection to database when my program is stopped manually by me. does finally statement do that for me? Like this: try: while true: do_something_with_database() finally: connection_to_database.close() considering that the while loop is infinite until i stop program manually. Any other idea? Tnx
1 ответ
+ 1
Well, the program will do the finally code for you, but it also will get a KeyboarInterrupt error, besides, there might be some platform-specific and user-specific issues. By all means I believe this is a bad idea to interrupt programm execution manually - you'd better do some programmable user iteraction or some kind of watchdog system to interrupt programm by event.