From 053f434e0466f503fba8b41d3d7f82aa6450a7be Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Fri, 2 Feb 2018 12:44:43 +0100 Subject: [PATCH] Download fixes - don't make empty requests - don't make requests if all objects are pending already --- src/network/downloadthread.py | 2 ++ src/randomtrackingdict.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/network/downloadthread.py b/src/network/downloadthread.py index 37e36398..88f7c12e 100644 --- a/src/network/downloadthread.py +++ b/src/network/downloadthread.py @@ -62,6 +62,8 @@ class DownloadThread(threading.Thread, StoppableThread): continue payload.extend(chunk) missingObjects[chunk] = now + if not payload: + continue i.append_write_buf(protocol.CreatePacket('getdata', payload)) logger.debug("%s:%i Requesting %i objects", i.destination.host, i.destination.port, len(request)) requested += len(request) diff --git a/src/randomtrackingdict.py b/src/randomtrackingdict.py index a7961528..83d35cdf 100644 --- a/src/randomtrackingdict.py +++ b/src/randomtrackingdict.py @@ -71,8 +71,9 @@ class RandomTrackingDict(object): self.pendingTimeout = pendingTimeout def randomKeys(self, count=1): - if self.len == 0 or (self.pendingLen >= self.maxPending and - self.lastPoll + self.pendingTimeout > time()): + if self.len == 0 or ((self.pendingLen >= self.maxPending or + self.pendingLen == self.len) and self.lastPoll + + self.pendingTimeout > time()): raise KeyError # reset if we've requested all with self.lock: