From b750e67bfbd741ebf415067c2e58953d34679e67 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sun, 15 Jan 2017 22:25:09 +0100 Subject: [PATCH] Handle exception in iterator --- src/inventory.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/inventory.py b/src/inventory.py index 0e81e756..b8b29fea 100644 --- a/src/inventory.py +++ b/src/inventory.py @@ -123,12 +123,16 @@ class Missing(object): with self.lock: since = time.time() - 60 # once every minute objectHashes = [] - for objectHash in self.hashes.keys(): - if current_thread().peer in self.hashes[objectHash]['peers'] and self.hashes[objectHash]['requested'] < since: - objectHashes.append(objectHash) - self.removeObjectFromCurrentThread(objectHash) - if len(objectHashes) >= count: - break + try: + for objectHash in self.hashes.keys(): + if current_thread().peer in self.hashes[objectHash]['peers'] and self.hashes[objectHash]['requested'] < since: + 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 def delete(self, objectHash):