title: How do I capture SIGINT in Python?
body: <p>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 <kbd>Ctrl</kbd>+<kbd>C</kbd> signal, and I'd like to do some cleanup.</p>
  
  <p>In Perl I'd do this:</p>
  
  <pre class="lang-perl prettyprint-override"><code>$SIG{'INT'} = 'exit_gracefully';
  
  sub exit_gracefully {
      print "Caught ^C \n";
      exit (0);
  }
  </code></pre>
  
  <p>How do I do the analogue of this in Python?</p>