From d04c0e78e44b1269de1008a24bc129a2ee95f800 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sun, 15 Jan 2017 22:36:12 +0100 Subject: [PATCH] Better handling of pending downloading objects --- src/inventory.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/inventory.py b/src/inventory.py index b8b29fea..fcc1ac94 100644 --- a/src/inventory.py +++ b/src/inventory.py @@ -86,6 +86,7 @@ class Inventory(collections.MutableMapping): @Singleton class Missing(object): + frequency = 60 def __init__(self): super(self.__class__, self).__init__() self.lock = RLock() @@ -112,7 +113,7 @@ class Missing(object): return except ValueError: pass - if len(self.hashes[objectHash]['peers']) == 0: + if len(self.hashes[objectHash]['peers']) == 0 and self.hashes[objectHash]['requested'] < time.time() - Missing.frequency: self.delete(objectHash) else: self.hashes[objectHash]['requested'] = time.time() @@ -121,11 +122,10 @@ class Missing(object): if count < 1: raise ValueError("Must be at least one") with self.lock: - since = time.time() - 60 # once every minute objectHashes = [] try: for objectHash in self.hashes.keys(): - if current_thread().peer in self.hashes[objectHash]['peers'] and self.hashes[objectHash]['requested'] < since: + if current_thread().peer in self.hashes[objectHash]['peers'] and self.hashes[objectHash]['requested'] < time.time() - Missing.frequency: objectHashes.append(objectHash) self.removeObjectFromCurrentThread(objectHash) if len(objectHashes) >= count: