diff options
author | John Garland <johnnybg@gmail.com> | 2012-02-16 14:12:03 +1100 |
---|---|---|
committer | John Garland <johnnybg@gmail.com> | 2012-02-16 14:12:03 +1100 |
commit | 08a75bd9f9f58988bde8661897b16d8b288c14f4 (patch) | |
tree | a701b2d8137963a52016cb240580e65e5a051261 | |
parent | 754a5a7f8a2d3f168824dd756d652463da082c03 (diff) | |
download | deluge-08a75bd9f9f58988bde8661897b16d8b288c14f4.tar.gz deluge-08a75bd9f9f58988bde8661897b16d8b288c14f4.tar.bz2 deluge-08a75bd9f9f58988bde8661897b16d8b288c14f4.zip |
Wait for client to shutdown/disconnect before stopping reactor (fixes #2032)
-rw-r--r-- | deluge/ui/gtkui/mainwindow.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/deluge/ui/gtkui/mainwindow.py b/deluge/ui/gtkui/mainwindow.py index 5b365e41c..910459d18 100644 --- a/deluge/ui/gtkui/mainwindow.py +++ b/deluge/ui/gtkui/mainwindow.py @@ -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"] |