fix synchronizer hanging when not connected.
This commit is contained in:
parent
c3cba78659
commit
a4cb70649d
|
@ -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:
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue