How can I clean stuff up on program exit?
<p>I have a command line program that wants to pickle things when I send it a ctrl-C via the terminal. I have a some questions and concerns: </p>

<ol>
<li><p>How do I perform this handling? Do I check for a KeyboardInterrupt? Is there a way to implement an exit function? </p></li>
<li><p>What if the program is halted in the middle of a write to a structure that I'm writing to? I presume these writes aren't treated atomically, so then how can I keep from writing trash into the pickle file? </p></li>
</ol>
