fix shutdown not being called when killed
This commit is contained in:
parent
465d98eeed
commit
fac65e9bb0
|
@ -26,7 +26,6 @@ import os
|
||||||
import time
|
import time
|
||||||
import locale
|
import locale
|
||||||
import shutil
|
import shutil
|
||||||
import signal
|
|
||||||
import urllib
|
import urllib
|
||||||
import gettext
|
import gettext
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -36,7 +35,7 @@ import mimetypes
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
from twisted.application import service, internet
|
from twisted.application import service, internet
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor, error
|
||||||
from twisted.web import http, resource, server, static
|
from twisted.web import http, resource, server, static
|
||||||
|
|
||||||
from deluge import common, component
|
from deluge import common, component
|
||||||
|
@ -325,21 +324,9 @@ class DelugeWeb(component.Component):
|
||||||
self.port = self.config["port"]
|
self.port = self.config["port"]
|
||||||
self.web_api = WebApi()
|
self.web_api = WebApi()
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, self.shutdown)
|
# Since twisted assigns itself all the signals may as well make
|
||||||
signal.signal(signal.SIGTERM, self.shutdown)
|
# use of it.
|
||||||
if not common.windows_check():
|
reactor.addSystemEventTrigger("after", "shutdown", self.shutdown)
|
||||||
signal.signal(signal.SIGHUP, self.shutdown)
|
|
||||||
else:
|
|
||||||
from win32api import SetConsoleCtrlHandler
|
|
||||||
from win32con import CTRL_CLOSE_EVENT
|
|
||||||
from win32con import 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()
|
||||||
|
@ -351,12 +338,15 @@ class DelugeWeb(component.Component):
|
||||||
self.port, self.port)
|
self.port, self.port)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
def shutdown(self, *args):
|
def shutdown(self):
|
||||||
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()
|
||||||
log.debug("Stopping reactor")
|
|
||||||
reactor.stop()
|
try:
|
||||||
|
reactor.stop()
|
||||||
|
except error.ReactorNotRunning:
|
||||||
|
log.debug("Tried to stop the reactor but it is not running..")
|
||||||
|
|
||||||
if __name__ == "__builtin__":
|
if __name__ == "__builtin__":
|
||||||
deluge_web = DelugeWeb()
|
deluge_web = DelugeWeb()
|
||||||
|
|
Loading…
Reference in New Issue