From 4b40d4bce1a9a23abda072d502a5e2adc89e7498 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sun, 22 Oct 2017 15:28:30 +0200 Subject: [PATCH] Download thread error handling --- src/network/downloadthread.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/network/downloadthread.py b/src/network/downloadthread.py index 7cbe11ad..414aacd2 100644 --- a/src/network/downloadthread.py +++ b/src/network/downloadthread.py @@ -47,11 +47,17 @@ class DownloadThread(threading.Thread, StoppableThread): timedOut = now - DownloadThread.requestTimeout # this may take a while, but it needs a consistency so I think it's better to lock a bigger chunk with i.objectsNewToMeLock: - downloadPending = len(list((k for k, v in i.objectsNewToMe.iteritems() if k in missingObjects and missingObjects[k] > timedOut))) + try: + downloadPending = len(list((k for k, v in i.objectsNewToMe.iteritems() if k in missingObjects and missingObjects[k] > timedOut))) + except KeyError: + continue if downloadPending >= DownloadThread.minPending: continue # keys with True values in the dict - request = list((k for k, v in i.objectsNewToMe.iteritems() if k not in missingObjects or missingObjects[k] < timedOut)) + try: + request = list((k for k, v in i.objectsNewToMe.iteritems() if k not in missingObjects or missingObjects[k] < timedOut)) + except KeyError: + continue random.shuffle(request) if not request: continue