[Twisted-Python] redefine signal handlers

Gabriel Rossetti gabriel.rossetti at arimaz.com
Wed Feb 4 03:15:38 MST 2009


Hello everyone,

I would like to run some cleanup code when my Twisted app receives a 
signal (SIGINT/SIGBREAK/SIGTERM).

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.")
        self.callFromThread(self.stop)

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

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

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,
Gabriel





More information about the Twisted-Python mailing list