diff --git a/deluge/ui/gtkui/signals.py b/deluge/ui/gtkui/signals.py index 0f3e594dd..b7021619f 100644 --- a/deluge/ui/gtkui/signals.py +++ b/deluge/ui/gtkui/signals.py @@ -44,13 +44,14 @@ class Signals(component.Component): component.Component.__init__(self, "Signals") self.receiver = SignalReceiver() self.config = ConfigManager("gtkui.conf") + self.config["signal_port"] = self.receiver.get_port() + self.config.save() def start(self): if not client.is_localhost(): self.receiver.set_remote(True) self.receiver.run() - self.config["signal_port"] = self.receiver.get_port() self.receiver.connect_to_signal("torrent_added", self.torrent_added_signal) self.receiver.connect_to_signal("torrent_removed", diff --git a/deluge/ui/signalreceiver.py b/deluge/ui/signalreceiver.py index dce443077..143f81041 100644 --- a/deluge/ui/signalreceiver.py +++ b/deluge/ui/signalreceiver.py @@ -50,8 +50,6 @@ class SignalReceiver(ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer): def __init__(self): log.debug("SignalReceiver init..") - # gobject.threads_init() - # Set to true so that the receiver thread will exit self._shutdown = False @@ -59,7 +57,29 @@ class SignalReceiver(ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer): self.emitted_signals = [] self.remote = False - + + # Setup the xmlrpc server + host = "localhost" + if self.remote == True: + host = "" + + server_ready = False + while not server_ready: + port = random.randint(40000, 65535) + try: + SimpleXMLRPCServer.SimpleXMLRPCServer.__init__( + self, (host, port), logRequests=False, allow_none=True) + except socket.error, e: + log.debug("Trying again with another port: %s", e) + except: + log.error("Could not start SignalReceiver XMLRPC server: %s", e) + sys.exit(0) + else: + self.port = port + server_ready = True + + # Register the emit_signal function + self.register_function(self.emit_signal) def shutdown(self): """Shutdowns receiver thread""" @@ -83,29 +103,6 @@ class SignalReceiver(ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer): def run(self): """This gets called when we start the thread""" - host = "localhost" - if self.remote == True: - host = "" - - # Setup the xmlrpc server - server_ready = False - while not server_ready: - port = random.randint(40000, 65535) - try: - SimpleXMLRPCServer.SimpleXMLRPCServer.__init__( - self, (host, port), logRequests=False, allow_none=True) - except socket.error, e: - log.debug("Trying again with another port: %s", e) - except: - log.error("Could not start SignalReceiver XMLRPC server: %s", e) - sys.exit(0) - else: - self.port = port - server_ready = True - - # Register the emit_signal function - self.register_function(self.emit_signal) - # Register the signal receiver with the core client.register_client(str(self.port))