[Twisted-Python] redefine signal handlers

Gabriel Rossetti gabriel.rossetti at arimaz.com
Wed Feb 4 05:15:38 EST 2009

Hello everyone,

I would like to run some cleanup code when my Twisted app receives a 

I saw that "_SignalReactorMixin" sets the handlers and that 
"ReactorBase" defines the default handlers :

     def sigInt(self, *args):
        """Handle a SIGINT interrupt.
        log.msg("Received SIGINT, shutting down.")

    def sigBreak(self, *args):
        """Handle a SIGBREAK interrupt.
        log.msg("Received SIGBREAK, shutting down.")

    def sigTerm(self, *args):
        """Handle a SIGTERM interrupt.
        log.msg("Received SIGTERM, shutting down.")

My question is how can I redefine them, other than monkey patching or 
inheriting the reactor and over-riding them (which I'd rather not do 
since some of my code uses the windows reactor when on windows since I 
was having problems with windows event)? Is there such a mechanism, 
something like setDefaultSig("SIGINT, mySigIntHandler)?

Thank you,

More information about the Twisted-Python mailing list