Skip to content

Commit

Permalink
fix aborting requests
Browse files Browse the repository at this point in the history
  • Loading branch information
minorua committed Mar 23, 2016
1 parent 20fcf1f commit 0ac84e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
13 changes: 10 additions & 3 deletions downloader.py
Expand Up @@ -124,14 +124,21 @@ def timeOut(self):
self.errorStatus = Downloader.TIMEOUT_ERROR

@pyqtSlot()
def abort(self):
# clear queue and abort sent requests
def abort(self, stopTimer=True):
# clear queue and abort requests
self.queue = []
self.timer.stop()

for reply in self.requestingReplies.itervalues():
url = reply.url().toString()
reply.abort()
reply.deleteLater()
self.log("request aborted: {0}".format(url))

self.errorStatus = Downloader.UNKNOWN_ERROR
self.requestingReplies = {}

if stopTimer:
self.timer.stop()

def fetchNext(self):
if len(self.queue) == 0:
Expand Down
14 changes: 9 additions & 5 deletions tilelayer.py
Expand Up @@ -280,7 +280,7 @@ def draw(self, renderContext):
if self.downloader.errorStatus != Downloader.NO_ERROR:
if self.downloader.errorStatus == Downloader.TIMEOUT_ERROR:
barmsg = self.tr("Download Timeout - {0}").format(self.name())
else:
elif stats["errors"] > 0:
msg += self.tr(" {0} files failed.").format(stats["errors"])
if stats["successed"] + allCacheHits == 0:
barmsg = self.tr("Failed to download all {0} files. - {1}").format(stats["errors"], self.name())
Expand Down Expand Up @@ -583,10 +583,14 @@ def fetchFiles(self, urls):
tick += 1
watchTimer.stop()

if tick == timeoutTick and downloader.unfinishedCount() > 0:
self.log("fetchFiles timeout")
QMetaObject.invokeMethod(downloader, "abort", Qt.QueuedConnection)
downloader.errorStatus = Downloader.TIMEOUT_ERROR
if downloader.unfinishedCount() > 0:
downloader.abort(False)
if self.renderContext.renderingStopped():
self.log("fetchFiles(): renderingStopped")

elif tick == timeoutTick:
downloader.errorStatus = Downloader.TIMEOUT_ERROR
self.log("fetchFiles(): timeout")

# watchTimer.timeout.disconnect(eventLoop.quit)
# downloader.allRepliesFinished.disconnect(eventLoop.quit)
Expand Down

0 comments on commit 0ac84e8

Please sign in to comment.