[python-win32] Guaranteed cleanup code execution?

Ross Boylan ross at biostat.ucsf.edu
Tue Jan 12 01:35:35 CET 2010


Is there a way to ensure that some cleanup code will get run whenever my
process terminates?

I've tried signal and try:finally:, while noting that, e.g., atexit says
it doesn't handle interrupts.  I can catch many circumstances, but if I
kill the process from task manager my cleanup doesn't happen (at least,
print "I'm cleaning up" doesn't come out).

I don't see anything in win32api that looks appropriate, and I don't
know if Windows provides any sure way to do what I want.  There is a
call to handle some very abnormal exits, but they are sufficiently bad
that, like SIGSEGV, I don't want to run the cleanup code (even if I
can).

The process will eventually run as a service.  I assume there is some
protocol for managing normal service control manager requests to start
and stop.

Thanks for any pointers.
Ross Boylan



More information about the python-win32 mailing list