tdon't set network.interface to None when disconnetced - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 4446cf44c732f7829279599cda18ebb8d56d7c15 DIR parent 942d009661431b0fb6f3daa531d03cb345f8657d HTML Author: ThomasV <thomasv@gitorious> Date: Mon, 16 Dec 2013 19:18:57 +0100 don't set network.interface to None when disconnetced Diffstat: M lib/network.py | 35 ++++++++++++++++++------------- M lib/wallet.py | 5 ++--- 2 files changed, 22 insertions(+), 18 deletions(-) --- DIR diff --git a/lib/network.py b/lib/network.py t@@ -133,7 +133,7 @@ class Network(threading.Thread): if not choice_list: if not self.interfaces: # we are probably offline, retry later - self.disconnected_servers = [] + self.disconnected_servers = set([]) return server = random.choice( choice_list ) t@@ -172,12 +172,17 @@ class Network(threading.Thread): self.start_interfaces() threading.Thread.start(self) if wait: - if self.config.get('auto_cycle'): - while not self.is_connected(): - time.sleep(0.1) - else: - self.interface.connect_event.wait() - return self.interface.is_connected + return self.wait_until_connected() + + def wait_until_connected(self): + "wait until connection status is known" + if self.config.get('auto_cycle'): + while not self.is_connected(): + time.sleep(0.1) + else: + self.interface.connect_event.wait() + + return self.interface.is_connected def set_parameters(self, host, port, protocol, proxy, auto_connect): t@@ -193,11 +198,11 @@ class Network(threading.Thread): self.protocol = protocol for i in self.interfaces.values(): i.stop() if auto_connect: - self.interface = None + #self.interface = None return if auto_connect: - if not self.interface: + if not self.interface.s_connected: self.switch_to_random_interface() else: if self.server_lag > 0: t@@ -211,7 +216,7 @@ class Network(threading.Thread): self.switch_to_interface(random.choice(self.interfaces.values())) def switch_to_interface(self, interface): - assert self.interface is None + assert not self.interface.is_connected server = interface.server print_error("switching to", server) self.interface = interface t@@ -226,17 +231,17 @@ class Network(threading.Thread): def stop_interface(self): self.interface.stop() - self.interface = None + #self.interface = None def set_server(self, server): - if self.default_server == server and self.interface: + if self.default_server == server and self.interface.is_connected: return if self.protocol != server.split(':')[2]: return # stop the interface in order to terminate subscriptions - if self.interface: + if self.interface.is_connected: self.stop_interface() # notify gui t@@ -307,10 +312,10 @@ class Network(threading.Thread): if i.server in self.heights: self.heights.pop(i.server) if i == self.interface: - self.interface = None + #self.interface = None self.trigger_callback('disconnected') - if self.interface is None and self.config.get('auto_cycle'): + if not self.interface.is_connected and self.config.get('auto_cycle'): self.switch_to_random_interface() DIR diff --git a/lib/wallet.py b/lib/wallet.py t@@ -1628,10 +1628,9 @@ class WalletSynchronizer(threading.Thread): self.running = True while self.is_running(): - + if not self.network.is_connected(): - print_error("synchronizer: waiting for interface") - self.network.interface.connect_event.wait() + self.network.wait_until_connected() self.run_interface(self.network.interface)