From aa9161a83a8217e3ef8ddac540dfac52d6f3caff Mon Sep 17 00:00:00 2001 From: HelloZeroNet Date: Thu, 5 May 2016 12:11:07 +0200 Subject: [PATCH] Check optional files findhash result every second --- src/Worker/WorkerManager.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Worker/WorkerManager.py b/src/Worker/WorkerManager.py index 6da24e7d..9036bc5c 100644 --- a/src/Worker/WorkerManager.py +++ b/src/Worker/WorkerManager.py @@ -251,15 +251,23 @@ class WorkerManager: for peer in peers: threads.append(gevent.spawn(peer.findHashIds, list(optional_hash_ids))) - gevent.joinall(threads, timeout=5) + for i in range(5): + time.sleep(1) + thread_values = [thread.value for thread in threads if thread.value] + if not thread_values: + continue - found_ips = helper.mergeDicts([thread.value for thread in threads if thread.value]) - found = self.addOptionalPeers(found_ips) - self.log.debug("Found optional files after findhash connected peers: %s/%s" % (len(found), len(optional_hash_ids))) + found_ips = helper.mergeDicts(thread_values) + found = self.addOptionalPeers(found_ips) + self.log.debug("Found optional files after findhash connected peers: %s/%s" % (len(found), len(optional_hash_ids))) - if found: - found_peers = set([peer for hash_id_peers in found.values() for peer in hash_id_peers]) - self.startWorkers(found_peers) + if found: + found_peers = set([peer for hash_id_peers in found.values() for peer in hash_id_peers]) + self.startWorkers(found_peers) + + if len(thread_values) == len(threads): + # Got result from all started thread + break if len(found) < len(optional_hash_ids): self.log.debug("No findHash result, try random peers: %s" % (optional_hash_ids - set(found)))