electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit a4cb70649d1c1a144f28561a261b237875680094
parent c3cba786593b28d3c9d9d2084d61eea8b89f0461
Author: ThomasV <thomasv@gitorious>
Date:   Sat, 14 Mar 2015 08:43:43 +0100

fix synchronizer hanging when not connected.

Diffstat:
Mlib/blockchain.py | 6++++--
Mlib/network.py | 6++----
Mlib/network_proxy.py | 3+--
Mlib/synchronizer.py | 5++++-
Mlib/util.py | 3+++
Mlib/verifier.py | 7++++---
6 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/lib/blockchain.py b/lib/blockchain.py @@ -41,7 +41,7 @@ class Blockchain(util.DaemonThread): def run(self): self.init_headers_file() self.set_local_height() - print_error( "blocks:", self.local_height ) + self.print_error("%d blocks"%self.local_height) while self.is_running(): try: @@ -77,6 +77,8 @@ class Blockchain(util.DaemonThread): continue self.network.new_blockchain_height(height, i) + self.print_error("stopped") + def verify_chain(self, chain): @@ -267,7 +269,7 @@ class Blockchain(util.DaemonThread): i.send_request({'method':'blockchain.block.get_header', 'params':[h]}, queue) def retrieve_request(self, queue): - while True: + while self.is_running(): try: ir = queue.get(timeout=1) except Queue.Empty: diff --git a/lib/network.py b/lib/network.py @@ -166,10 +166,6 @@ class Network(util.DaemonThread): self.requests_queue = Queue.Queue() self.set_proxy(deserialize_proxy(self.config.get('proxy'))) - - def print_error(self, *msg): - util.print_error("[network]", *msg) - def get_server_height(self): return self.heights.get(self.default_server, 0) @@ -502,6 +498,8 @@ class Network(util.DaemonThread): for i in self.interfaces.values(): i.stop() + self.print_error("stopped") + def on_header(self, i, r): result = r.get('result') diff --git a/lib/network_proxy.py b/lib/network_proxy.py @@ -78,11 +78,10 @@ class NetworkProxy(util.DaemonThread): if response is None: break self.process(response) - self.trigger_callback('stop') if self.network: self.network.stop() - print_error("NetworkProxy: terminating") + self.print_error("stopped") def process(self, response): if self.debug: diff --git a/lib/synchronizer.py b/lib/synchronizer.py @@ -49,8 +49,9 @@ class WalletSynchronizer(util.DaemonThread): def run(self): while self.is_running(): - while not self.network.is_connected(): + if not self.network.is_connected(): time.sleep(0.1) + continue self.run_interface() def run_interface(self): @@ -183,3 +184,5 @@ class WalletSynchronizer(util.DaemonThread): # Updated gets called too many times from other places as well; if we use that signal we get the notification three times self.network.trigger_callback("new_transaction") self.was_updated = False + + self.print_error("stopped") diff --git a/lib/util.py b/lib/util.py @@ -43,6 +43,9 @@ class DaemonThread(threading.Thread): with self.running_lock: self.running = False + def print_error(self, *msg): + print_error("[%s]"%self.__class__.__name__, *msg) + is_verbose = False diff --git a/lib/verifier.py b/lib/verifier.py @@ -97,13 +97,12 @@ class TxVerifier(util.DaemonThread): if self.network.send([ ('blockchain.transaction.get_merkle',[tx_hash, tx_height]) ], self.queue.put): print_error('requesting merkle', tx_hash) requested_merkle.append(tx_hash) - try: r = self.queue.get(timeout=0.1) except Queue.Empty: continue - - if not r: continue + if not r: + continue if r.get('error'): print_error('Verifier received an error:', r) @@ -118,6 +117,8 @@ class TxVerifier(util.DaemonThread): tx_hash = params[0] self.verify_merkle(tx_hash, result) + self.print_error("stopped") + def verify_merkle(self, tx_hash, result): tx_height = result.get('block_height')