mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-03 15:08:40 +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
|
@ -27,6 +27,7 @@ import time
|
||||||
import locale
|
import locale
|
||||||
import shutil
|
import shutil
|
||||||
import signal
|
import signal
|
||||||
|
import signal
|
||||||
import urllib
|
import urllib
|
||||||
import gettext
|
import gettext
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -349,6 +350,19 @@ class DelugeWeb(component.Component):
|
||||||
# use of it.
|
# 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
|
# Initalize the plugins
|
||||||
self.plugins = PluginManager()
|
self.plugins = PluginManager()
|
||||||
|
|
||||||
|
@ -359,10 +373,14 @@ class DelugeWeb(component.Component):
|
||||||
self.port, self.port)
|
self.port, self.port)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self, *args):
|
||||||
log.info("Shutting down webserver")
|
log.info("Shutting down webserver")
|
||||||
log.debug("Saving configuration file")
|
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__":
|
if __name__ == "__builtin__":
|
||||||
deluge_web = DelugeWeb()
|
deluge_web = DelugeWeb()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue