[Zope-Coders] Signal handling

Brian Lloyd brian@zope.com
Fri, 14 Jun 2002 12:02:02 -0400


> I have some products that have their own log files, and it would 
> be nice to 
> reopen those on a USR2 too. 
> 
> Any objections to the patch in http://collector.zope.org/Zope/430 ?

It seems like it would be good for this to be a more 
generalized facility, rather than adding more funny 
magic globals.

So I went ahead and did it :)

Chris, I refactored it so that the sig handling code 
that was in z2.py is now encapsulated in a singleton 
in a new module: SignalHandler.py.

The way it works now, the "standard" signal handlers 
that were in z2 are guaranteed to run, but users can 
now use the registerHander method to add handlers for 
given signals. For example:

from SignalHandler import SignalHandler
import signal

def mySigUsr2Handler():
  print 'hi, Im the SIGUSR2 handler!'

SignalHandler.registerHandler(signal.SIGUSR2, mySigUsr2Handler)


The only caveat is that for now you are restricted to 
SIGINT, SIGTERM, SIGUSR2 and SIGHUP. That's because 
of the way that signal pass-through is hooked up to 
zdaemon. The SignalHandler singleton can deal with 
any kind of signal, so if we ever care to figure this 
out we'll just need to revisit the way that zdaemon is 
notified of pass-through signals.



Brian Lloyd        brian@zope.com
V.P. Engineering   540.361.1716       
Zope Corporation   http://www.zope.com