mirror of
https://git.deluge-torrent.org/deluge
synced 2025-04-21 03:54:50 +00:00
fix handling close on windows
This commit is contained in:
parent
9f2b98bf4b
commit
725198fc4d
1 changed files with 22 additions and 4 deletions
|
@ -25,7 +25,8 @@
|
|||
import os
|
||||
import time
|
||||
import locale
|
||||
import shutil
|
||||
import shutil
|
||||
import signal
|
||||
import signal
|
||||
import urllib
|
||||
import gettext
|
||||
|
@ -347,7 +348,20 @@ class DelugeWeb(component.Component):
|
|||
|
||||
# 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 @@ class DelugeWeb(component.Component):
|
|||
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()
|
||||
|
|
Loading…
Add table
Reference in a new issue