Ticket #2692: patch

File patch, 2.5 KB (added by yaubi, 15 years ago)

Proposed patch

  • twisted/internet/base.py

     
    269269        self._newTimedCalls = []
    270270        self._cancellations = 0
    271271        self.running = 0
     272        self.shuttingDown = False
    272273        self.waker = None
    273274
    274275        self.addSystemEventTrigger('during', 'shutdown', self.crash)
     
    334335    def stop(self):
    335336        """See twisted.internet.interfaces.IReactorCore.stop.
    336337        """
     338        if self.shuttingDown:
     339            raise error.ReactorAlreadyStopped, "don't stop reactor twice"
    337340        if not self.running:
    338341            raise RuntimeError, "can't stop reactor that isn't running"
     342        self.shuttingDown = True
    339343        self.fireSystemEvent("shutdown")
    340344
    341345    def crash(self):
     
    346350    def sigInt(self, *args):
    347351        """Handle a SIGINT interrupt.
    348352        """
    349         log.msg("Received SIGINT, shutting down.")
    350         self.callFromThread(self.stop)
     353        if not self.shuttingDown:
     354            log.msg("Received SIGINT, shutting down.")
     355            self.callFromThread(self.stop)
     356        else:
     357            log.msg("Received SIGINT, discaring.")
    351358
    352359    def sigBreak(self, *args):
    353360        """Handle a SIGBREAK interrupt.
    354361        """
    355         log.msg("Received SIGBREAK, shutting down.")
    356         self.callFromThread(self.stop)
     362        if not self.shuttingDown:
     363            log.msg("Received SIGBREAK, shutting down.")
     364            self.callFromThread(self.stop)
     365        else:
     366            log.msg("Received SIGBREAK, discaring.")
    357367
    358368    def sigTerm(self, *args):
    359369        """Handle a SIGTERM interrupt.
    360370        """
    361         log.msg("Received SIGTERM, shutting down.")
    362         self.callFromThread(self.stop)
     371        if not self.shuttingDown:
     372            log.msg("Received SIGTERM, shutting down.")
     373            self.callFromThread(self.stop)
     374        else:
     375            log.msg("Received SIGTERM, discaring.")
    363376
    364377    def disconnectAll(self):
    365378        """Disconnect every reader, and writer in the system.
  • twisted/internet/error.py

     
    265265            s = '%s: %s' % (s, ' '.join(self.args))
    266266        s = '%s.' % s
    267267        return s
     268
     269
     270class ReactorAlreadyStopped(RuntimeError):
     271    """The reactor has already been asked to stop"""
     272