From 7847362dbbfee223545951e2bd91905673d36b70 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sun, 19 Feb 2012 16:44:12 +0000 Subject: [PATCH] Catch and log ReactorNotRunning when stopping reactor in gtk --- deluge/common.py | 2 +- deluge/ui/gtkui/gtkui.py | 2 +- deluge/ui/gtkui/ipcinterface.py | 16 ++++++++-------- deluge/ui/gtkui/mainwindow.py | 6 +++++- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/deluge/common.py b/deluge/common.py index a92b858ae..0ae8d5742 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -277,7 +277,7 @@ def fsize(fsize_b): return "%.1f %s" % (fsize_mb, _("MiB")) fsize_gb = fsize_mb / 1024.0 return "%.1f %s" % (fsize_gb, _("GiB")) - + def fsize_short(fsize_b): """ Formats the bytes value into a string with K, M or G units diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index bbb99ffcf..340b5fc87 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -289,7 +289,7 @@ class GtkUI(object): def on_dialog_response(response): if response != gtk.RESPONSE_YES: # The user does not want to turn Classic Mode off, so just quit - reactor.stop() + self.mainwindow.quit() return # Turning off classic_mode self.config["classic_mode"] = False diff --git a/deluge/ui/gtkui/ipcinterface.py b/deluge/ui/gtkui/ipcinterface.py index 45d87ae45..2569072a8 100644 --- a/deluge/ui/gtkui/ipcinterface.py +++ b/deluge/ui/gtkui/ipcinterface.py @@ -44,7 +44,7 @@ try: import rencode except ImportError: import deluge.rencode as rencode - + import deluge.component as component from deluge.ui.client import client import deluge.common @@ -64,11 +64,11 @@ class IPCProtocolClient(Protocol): def connectionMade(self): self.transport.write(rencode.dumps(self.factory.args)) self.transport.loseConnection() - + def connectionLost(self, reason): reactor.stop() self.factory.stop = True - + class IPCClientFactory(ClientFactory): protocol = IPCProtocolClient @@ -76,11 +76,11 @@ class IPCClientFactory(ClientFactory): self.stop = False self.args = args self.connect_failed = connect_failed - + def clientConnectionFailed(self, connector, reason): log.info("Connection to running instance failed. Starting new one..") reactor.stop() - + class IPCInterface(component.Component): def __init__(self, args): component.Component.__init__(self, "IPCInterface") @@ -151,14 +151,14 @@ class IPCInterface(component.Component): def connect_failed(self, args): # This gets called when we're unable to do a connectUNIX to the ipc # socket. We'll delete the lock and socket files and start up Deluge. - #reactor.stop() + socket = os.path.join(deluge.configmanager.get_config_dir("ipc"), "deluge-gtk") if os.path.exists(socket): try: os.remove(socket) except Exception, e: log.error("Unable to remove socket file: %s", e) - + lock = socket + ".lock" if os.path.lexists(lock): try: @@ -173,7 +173,7 @@ class IPCInterface(component.Component): log.error("Unable to start IPC listening socket: %s", e) finally: process_args(args) - + def shutdown(self): if deluge.common.windows_check(): import win32api diff --git a/deluge/ui/gtkui/mainwindow.py b/deluge/ui/gtkui/mainwindow.py index fec8af1bf..b456dc16a 100644 --- a/deluge/ui/gtkui/mainwindow.py +++ b/deluge/ui/gtkui/mainwindow.py @@ -45,6 +45,7 @@ import deluge.component as component from deluge.configmanager import ConfigManager from deluge.ui.gtkui.ipcinterface import process_args from twisted.internet import reactor, defer +from twisted.internet.error import ReactorNotRunning import deluge.common import common @@ -165,7 +166,10 @@ class MainWindow(component.Component): return client.disconnect() def stop_reactor(result): - return reactor.stop() + try: + reactor.stop() + except ReactorNotRunning: + log.debug("Attempted to stop the reactor but it is not running...") def log_failure(failure, action): log.error("Encountered error attempting to %s: %s" % \