Changeset 725198


Ignore:
Timestamp:
04/27/2009 06:46:30 PM (16 years ago)
Author:
Damien Churchill <damoc@gmail.com>
Branches:
2.0.x, develop, extjs4-port, master
Children:
2ac545d
Parents:
9f2b98
Message:

fix handling close on windows

File:
1 edited

Legend:

Unmodified
Added
Removed
  • deluge/ui/web/server.py

    r9f2b98 r725198  
    2727import locale
    2828import shutil
     29import signal
    2930import signal
    3031import urllib
     
    349350        # use of it.
    350351        reactor.addSystemEventTrigger("after", "shutdown", self.shutdown)
     352
     353        # Twisted doesn't handle windows specific signals so we still
     354        # need to attach to those to handle the close correctly.
     355        if common.windows_check():
     356            from win32api import SetConsoleCtrlHandler
     357            from win32con import CTRL_CLOSE_EVENT, CTRL_SHUTDOWN_EVENT
     358            def win_handler(ctrl_type):
     359                log.debug("ctrl type: %s", ctrl_type)
     360                if ctrl_type == CTRL_CLOSE_EVENT or \
     361                   ctrl_type == CTRL_SHUTDOWN_EVENT:
     362                    self.shutdown()
     363                    return 1
     364            SetConsoleCtrlHandler(win_handler)
    351365       
    352366        # Initalize the plugins
     
    360374        reactor.run()
    361375
    362     def shutdown(self):
     376    def shutdown(self, *args):
    363377        log.info("Shutting down webserver")
    364378        log.debug("Saving configuration file")
    365379        self.config.save()
     380        try:
     381            reactor.stop()
     382        except error.ReactorNotRunning:
     383            log.debug("Reactor not running")
    366384
    367385if __name__ == "__builtin__":
Note: See TracChangeset for help on using the changeset viewer.