Handle exception in iterator

This commit is contained in:
Peter Šurda 2017-01-15 22:25:09 +01:00
parent 805f72e098
commit b750e67bfb
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -123,12 +123,16 @@ class Missing(object):
with self.lock: with self.lock:
since = time.time() - 60 # once every minute since = time.time() - 60 # once every minute
objectHashes = [] objectHashes = []
for objectHash in self.hashes.keys(): try:
if current_thread().peer in self.hashes[objectHash]['peers'] and self.hashes[objectHash]['requested'] < since: for objectHash in self.hashes.keys():
objectHashes.append(objectHash) if current_thread().peer in self.hashes[objectHash]['peers'] and self.hashes[objectHash]['requested'] < since:
self.removeObjectFromCurrentThread(objectHash) objectHashes.append(objectHash)
if len(objectHashes) >= count: self.removeObjectFromCurrentThread(objectHash)
break if len(objectHashes) >= count:
break
except RuntimeError:
# the for cycle sometimes breaks if you remove elements
pass
return objectHashes return objectHashes
def delete(self, objectHash): def delete(self, objectHash):