Author: damoxc

Revision: 5191

Log:
        fix handling close on windows

Diff:
Modified: trunk/deluge/ui/web/server.py
===================================================================
--- trunk/deluge/ui/web/server.py       2009-04-27 18:26:40 UTC (rev 5190)
+++ trunk/deluge/ui/web/server.py       2009-04-27 18:46:30 UTC (rev 5191)
@@ -25,8 +25,9 @@
 import os
 import time
 import locale
-import shutil
+import shutil
 import signal
+import signal
 import urllib
 import gettext
 import hashlib
@@ -347,7 +348,20 @@
         
         # Since twisted assigns itself all the signals may as well make
         # use of it.
-        reactor.addSystemEventTrigger("after", "shutdown", self.shutdown)
+        reactor.addSystemEventTrigger("after", "shutdown", self.shutdown)
+
+        # Twisted doesn't handle windows specific signals so we still
+        # need to attach to those to handle the close correctly.
+        if common.windows_check():
+            from win32api import SetConsoleCtrlHandler
+            from win32con import CTRL_CLOSE_EVENT, CTRL_SHUTDOWN_EVENT
+            def win_handler(ctrl_type):
+                log.debug("ctrl type: %s", ctrl_type)
+                if ctrl_type == CTRL_CLOSE_EVENT or \
+                   ctrl_type == CTRL_SHUTDOWN_EVENT:
+                    self.shutdown()
+                    return 1
+            SetConsoleCtrlHandler(win_handler)
         
         # Initalize the plugins
         self.plugins = PluginManager()
@@ -359,10 +373,14 @@
             self.port, self.port)
         reactor.run()
 
-    def shutdown(self):
+    def shutdown(self, *args):
         log.info("Shutting down webserver")
         log.debug("Saving configuration file")
-        self.config.save()
+        self.config.save()
+        try:
+            reactor.stop()
+        except error.ReactorNotRunning:
+            log.debug("Reactor not running")
 
 if __name__ == "__builtin__":
     deluge_web = DelugeWeb()



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to