Handling signals and performance issues.

Roy Smith roy at panix.com
Sat Dec 9 20:53:50 EST 2000


> My second problem is that while the program handles a CTRL-C, etc 
> well-- cleaning up and the like, if it is sent a kill -9 or kill -HUP 
> by root or the user spawning the process it dies a horrible 
> death--ie, it doesn't clean up and flush its buffers, or run the 
> 'cleanup' functions I've defined with a try: except: block.

You cannot catch a kill -9 signal.  It is the "signal of last resort", a 
way to kill a process regardless of what it has done to itself in the 
way of signal processing/catching/ignoring.  This is as true in python 
as in any other language.

There always has to be some sort of un-catchable signal, otherwise a 
process would be able to make itself completely immune to being killed.  
There are still ways to make processes unkillable, but they all involve 
tickling kernel bugs :-)

As for watching the end of a log file without burning CPU, as somebody 
else already mentioned, sleeping for a second between reads would be one 
good way.  Another thing you might try is using a select() call to tell 
you when new data is readable on the file.

You might want to look at the source to the unix "tail" command (you 
should be able to find it on any of the many GNU/Linux distribution 
sites) and see how it implements the "-f" option, which is essentially 
what you are trying to emulate.



More information about the Python-list mailing list