title: Making a python cgi script to finish gracefully
body: <p>I have a python cgi script that accepts user uploads (via sys.stdin.read).
  After receiving the file (whether successfully or unsuccessfully), the script needs to do some cleanup. This works fine when upload finishes correctly, however if the user closes the client, the cgi script is silently killed on the server, and as a result no cleanup code gets executed. How can i force the script to always finish.</p>