Capturing terminate command from script

  • Javier

    Javier - 2006-08-16

    I have a python script that uses a database. The database is closed in, among other places, the KeyboardInterrupt exception handler, which when running the script from the Linux shell is raised when the user presses Ctrl+C. My problem is that, periodically, I'm getting a database corruption error, caused by the database not have been closed properly, which requires the DB file to be deleted and re-created.
    The database is, in fact, not closed, when terminating the script from within Eclipse (using the red square button of Pydev console). The KeyboardInterrupt exception doesn't seem to be thrown, and the close() function call in its handler is not executed.
    Any light on how to solve this?.
    Thanks a lot.

    • Fabio Zadrozny

      Fabio Zadrozny - 2006-08-19

      Well, when you use the red square button of Pydev, it does not actually throw a KeyboardInterrupt exception... It sends a kill message to the system (which will in turn kill your program)...

      It would be like sending a SIGTERM to the python shell.

      Now, this gets to an interesting point... the Eclipse console is not actually a full implementation of a shell, you're not able to send a Ctrl+C to the console.  (There's already a bug for that in

      So, your implementation won't work correctly inside Eclipse... I think the best choice you'd have is making your application handle text inputs, so that you could type 'exit' and then it would exit instead of using a keyboard interrupt for that.




Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks