tfix disconnection error - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 411a87e0a3d9bfe6a3d84a16aa2d524a545b0a77 DIR parent 1c707d05d37ad87c2bfb8317c4b2351891385768 HTML Author: ThomasV <thomasv@gitorious> Date: Tue, 29 Jul 2014 14:19:23 +0200 fix disconnection error Diffstat: M lib/interface.py | 9 +++++---- M lib/network.py | 14 +++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) --- DIR diff --git a/lib/interface.py b/lib/interface.py t@@ -252,7 +252,11 @@ class TcpInterface(threading.Thread): method = request.get('method') params = request.get('params') with self.lock: - self.pipe.send({'id':self.message_id, 'method':method, 'params':params}) + try: + self.pipe.send({'id':self.message_id, 'method':method, 'params':params}) + except socket.error: + self.is_connected = False + return self.unanswered_requests[self.message_id] = method, params, _id, queue self.message_id += 1 if self.debug: t@@ -283,9 +287,6 @@ class TcpInterface(threading.Thread): self.s.close() self.is_connected = False - def is_up_to_date(self): - return self.unanswered_requests == {} - def start(self, response_queue): self.response_queue = response_queue threading.Thread.start(self) DIR diff --git a/lib/network.py b/lib/network.py t@@ -135,17 +135,12 @@ class Network(threading.Thread): def is_connected(self): return self.interface and self.interface.is_connected - def is_up_to_date(self): - raise - return self.interface.is_up_to_date() - def send_subscriptions(self): for addr in self.addresses: self.interface.send_request({'method':'blockchain.address.subscribe', 'params':[addr]}) self.interface.send_request({'method':'server.banner','params':[]}) self.interface.send_request({'method':'server.peers.subscribe','params':[]}) - def get_status_value(self, key): if key == 'status': value = self.connection_status t@@ -255,8 +250,13 @@ class Network(threading.Thread): def switch_to_random_interface(self): - if self.interfaces: - self.switch_to_interface(random.choice(self.interfaces.values())) + while True: + i = random.choice(self.interfaces.values()) + if i.is_connected: + self.switch_to_interface(i) + break + else: + time.sleep(0.1) def switch_to_interface(self, interface): server = interface.server