27-07-2009 Ben Finney <ben+pyt...@benfinney.id.au> wrote:

David <71da...@libero.it> 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:http://docs.python.org/library/atexit> to register yours for
processing whenever the program exits.

Unfortunately neither sys.exitfunc nor function registered with
atexit.register() are called when process is killed with signal.

As I wrote, you must use signals. Though sometimes it's a good idea
to combine these two techniques (i.e. signal handlers call sys.exit(),
then sys.exitfunc/or function registered with atexit does the actual
cleaning actions).

*j

--
Jan Kaliszewski (zuo) <z...@chopin.edu.pl>
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to