Gracefully exiting CLI application

Ben Finney ben+python at
Mon Jul 27 23:40:32 CEST 2009

David <71david at> writes:

> I am writing a command line application, and I need to perform some
> cleaning on exit even if the process is killed. How can I do that with
> python?

Write an “exit handler” function, then use ‘atexit.register’
<URL:> to register yours for
processing whenever the program exits.

 \        “Pinky, are you pondering what I'm pondering?” “Wuh, I think |
  `\    so, Brain, but will they let the Cranberry Duchess stay in the |
_o__)                         Lincoln Bedroom?” —_Pinky and The Brain_ |
Ben Finney

More information about the Python-list mailing list