From 0676aaf9187f68aa74cfb256aad3e6ea3280f12b Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Fri, 2 Mar 2012 09:15:35 -0800 Subject: [PATCH] Properly wait for the component.shutdown deferred on shutdown. This should prevent the daemon from exiting before all the state has been saved. --- deluge/core/daemon.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/deluge/core/daemon.py b/deluge/core/daemon.py index 500f5da39..bac5b6998 100644 --- a/deluge/core/daemon.py +++ b/deluge/core/daemon.py @@ -110,7 +110,7 @@ class Daemon(object): # Twisted catches signals to terminate, so just have it call the shutdown # method. - reactor.addSystemEventTrigger("after", "shutdown", self.shutdown) + reactor.addSystemEventTrigger("before", "shutdown", self._shutdown) # Catch some Windows specific signals if deluge.common.windows_check(): @@ -182,17 +182,16 @@ class Daemon(object): reactor.callLater(0, reactor.stop) def _shutdown(self, *args, **kwargs): - try: - os.remove(deluge.configmanager.get_config_dir("deluged.pid")) - except Exception, e: - log.exception(e) - log.error("Error removing deluged.pid!") + if os.path.exists(deluge.configmanager.get_config_dir("deluged.pid")): + try: + os.remove(deluge.configmanager.get_config_dir("deluged.pid")) + except Exception, e: + log.exception(e) + log.error("Error removing deluged.pid!") - component.shutdown() - try: - reactor.stop() - except twisted.internet.error.ReactorNotRunning: - log.debug("Tried to stop the reactor but it is not running..") + log.info("Waiting for components to shutdown..") + d = component.shutdown() + return d @export() def info(self):