From 12205ee7baba3c1e8353deadedbc1b311721c5dd Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sun, 15 Jan 2017 23:07:11 +0100 Subject: [PATCH] More fixes in objects to be downloaded --- src/inventory.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/inventory.py b/src/inventory.py index d9fefdad..5e54f52b 100644 --- a/src/inventory.py +++ b/src/inventory.py @@ -121,23 +121,22 @@ class Missing(object): def pull(self, count=1): if count < 1: raise ValueError("Must be at least one") - with self.lock: - objectHashes = [] - try: - for objectHash in self.hashes.keys(): - if self.hashes[objectHash]['requested'] < time.time() - self.frequency: - if len(self.hashes[objectHash]['peers']) == 0: - self.removeObjectFromCurrentThread(objectHash) - continue - if current_thread().peer in self.hashes[objectHash]['peers']: - objectHashes.append(objectHash) - self.removeObjectFromCurrentThread(objectHash) - if len(objectHashes) >= count: - break - except RuntimeError: - # the for cycle sometimes breaks if you remove elements - pass - return objectHashes + objectHashes = [] + try: + for objectHash in self.hashes.keys(): + if self.hashes[objectHash]['requested'] < time.time() - self.frequency: + if len(self.hashes[objectHash]['peers']) == 0: + self.removeObjectFromCurrentThread(objectHash) + continue + if current_thread().peer in self.hashes[objectHash]['peers']: + objectHashes.append(objectHash) + self.removeObjectFromCurrentThread(objectHash) + if len(objectHashes) >= count: + break + except (RuntimeError, KeyError, ValueError): + # the for cycle sometimes breaks if you remove elements + pass + return objectHashes def delete(self, objectHash): with self.lock: