diff options
author | Gonzalo Odiard <godiard@sugarlabs.org> | 2011-05-16 21:10:24 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2011-08-08 13:41:09 (GMT) |
commit | 28037a9cb8a6890db4cb2d4438bac226b283c9d4 (patch) | |
tree | 7021279c84e16cea3e2765c3f838db4672490a44 /opds.py | |
parent | 1a93467d39a828444e7c1133b6f8500386f9151d (diff) |
Cancel previous download image threads
Signed-off-by: Daniel Castelo <dcastelo@plan.ceibal.edu.uy>
Acked-By: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'opds.py')
-rwxr-xr-x[-rw-r--r--] | opds.py | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -501,9 +501,17 @@ class ImageDownloaderThread(threading.Thread): def _get_image_result_cb(self, getter, tempfile, suggested_name): _logger.debug("Got Cover Image %s (%s)", tempfile, suggested_name) self._getter = None - gobject.idle_add(self.obj.notify_updated, tempfile) + if not self.stopthread.is_set(): + gobject.idle_add(self.obj.notify_updated, tempfile) def _get_image_progress_cb(self, getter, bytes_downloaded): + if self.stopthread.is_set(): + try: + _logger.debug('The download %s was cancelled' % getter._fname) + getter.cancel() + except: + _logger.debug('Got an exception while trying ' + \ + 'to cancel download') if self._download_content_length > 0: _logger.debug("Downloaded %u of %u bytes...", bytes_downloaded, self._download_content_length) @@ -549,3 +557,7 @@ class ImageDownloader(gobject.GObject): def notify_updated(self, temp_file): self.emit('updated', temp_file) + + def stop_download(self): + for thread in self.threads: + thread.stop() |