I'm working on a python script that starts several processes and database connections. Every now and then I want to kill the script with a Ctrl+C signal, and I'd like to do some cleanup. In Perl I'd do this:
Register your handler with signal.signal like this:
More documentation on module signal can be found here.
* Tutorialspoint - Unix - Signals and Traps