Skip to content
Advertisement

Tag: controls

How do I capture SIGINT in Python?

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: How do I do the analogue of this in Python? Answer Register your handler with signal.signal like this: Code adapted from

Advertisement