From 64c67a07ddbe89d8f8af3dbecfe7860909420da7 Mon Sep 17 00:00:00 2001 From: bendikro Date: Wed, 13 Apr 2016 21:01:27 +0200 Subject: [PATCH] [WebUI] Fix #2798: WebUI plugin fails to start --- .../WebUi/deluge/plugins/webui/core.py | 2 +- deluge/ui/web/server.py | 25 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/deluge/plugins/WebUi/deluge/plugins/webui/core.py b/deluge/plugins/WebUi/deluge/plugins/webui/core.py index 78294b6da..cf2811a81 100644 --- a/deluge/plugins/WebUi/deluge/plugins/webui/core.py +++ b/deluge/plugins/WebUi/deluge/plugins/webui/core.py @@ -71,7 +71,7 @@ class Core(CorePluginBase): self.server.port = self.config["port"] self.server.https = self.config["ssl"] - self.server.start(False) + self.server.start(standalone=False) return True @export diff --git a/deluge/ui/web/server.py b/deluge/ui/web/server.py index 31546401d..a6c8abdd9 100644 --- a/deluge/ui/web/server.py +++ b/deluge/ui/web/server.py @@ -544,7 +544,7 @@ class DelugeWeb(component.Component): self.base = self.config["base"] self.web_api = WebApi() self.auth = Auth(self.config) - + self.standalone = True # Initalize the plugins self.plugins = PluginManager() @@ -567,15 +567,31 @@ class DelugeWeb(component.Component): return 1 SetConsoleCtrlHandler(win_handler) - def start(self): + def start(self, standalone=True): + """ + Start the DelugeWeb server + + When running WebUI plugin, the server must not try to start + the twisted reactor. + + Args: + standalone (bool): Whether the server runs as a standalone process + If standalone, start twisted reactor. + + Returns: + Deferred + """ log.info("%s %s.", _("Starting server in PID"), os.getpid()) + self.standalone = standalone if self.https: self.start_ssl() else: self.start_normal() component.get("Web").enable() - reactor.run() + + if self.standalone: + reactor.run() def start_normal(self): self.socket = reactor.listenTCP(self.port, self.site, interface=self.interface) @@ -613,7 +629,8 @@ class DelugeWeb(component.Component): def shutdown(self, *args): self.stop() - reactor.stop() + if self.standalone: + reactor.stop() if __name__ == "__builtin__":