Wait for client to shutdown/disconnect before stopping reactor (fixes #2032)

This commit is contained in:
John Garland 2012-02-16 14:12:03 +11:00
parent 754a5a7f8a
commit 08a75bd9f9

View File

@ -44,7 +44,7 @@ from deluge.ui.client import client
import deluge.component as component
from deluge.configmanager import ConfigManager
from deluge.ui.gtkui.ipcinterface import process_args
from twisted.internet import reactor
from twisted.internet import reactor, defer
import deluge.common
import common
@ -157,12 +157,28 @@ class MainWindow(component.Component):
:param shutdown: whether or not to shutdown the daemon as well
:type shutdown: boolean
"""
def shutdown_daemon(result):
return client.daemon.shutdown()
def disconnect_client(result):
return client.disconnect()
def stop_reactor(result):
return reactor.stop()
def log_failure(failure, action):
log.error("Encountered error attempting to %s: %s" % \
(action, failure.getErrorMessage()))
d = defer.succeed(None)
if shutdown:
try:
client.daemon.shutdown()
except AttributeError, e:
log.error("Encountered error attempting to shutdown daemon: %s", e)
reactor.stop()
d.addCallback(shutdown_daemon)
d.addErrback(log_failure, "shutdown daemon")
if not client.is_classicmode() and client.connected():
d.addCallback(disconnect_client)
d.addErrback(log_failure, "disconnect client")
d.addBoth(stop_reactor)
def load_window_state(self):
x = self.config["window_x_pos"]