support jumps in limit downloads

like when unchecking 'limit downloads' or entering a value manually in limit downloads.
Fixes #340
This commit is contained in:
Eric Le Lay 2018-04-29 15:15:18 +02:00
parent f45ee07522
commit 740e6bd7f8
3 changed files with 20 additions and 12 deletions

View File

@ -401,12 +401,15 @@ class DownloadQueueManager(object):
"""Spawn new worker threads if necessary
"""
with self.worker_threads_access:
if not self.tasks.has_work():
return
if len(self.worker_threads) == 0 or \
len(self.worker_threads) < self._config.max_downloads or \
not self._config.max_downloads_enabled:
work_count = self.tasks.available_work_count()
if self._config.max_downloads_enabled:
# always allow at least 1 download
max_downloads = max(int(self._config.max_downloads), 1)
spawn_limit = max_downloads - len(self.worker_threads)
else:
spawn_limit = work_count
logger.info('%r tasks to do, can start at most %r threads', work_count, spawn_limit)
for i in range(0, min(work_count, spawn_limit)):
# We have to create a new thread here, there's work to do
logger.info('Starting new worker thread.')

View File

@ -142,18 +142,22 @@ class DownloadStatusModel(Gtk.ListStore):
return False
def has_work(self):
return any(task for task in
(row[DownloadStatusModel.C_TASK] for row in self)
if task.status == task.QUEUED)
return any(self._work_gen())
def available_work_count(self):
return len(list(self._work_gen()))
def get_next(self):
with self.set_downloading_access:
result = next(task for task in
(row[DownloadStatusModel.C_TASK] for row in self)
if task.status == task.QUEUED)
result = next(self._work_gen())
self.set_downloading(result)
return result
def _work_gen(self):
return (task for task in
(row[DownloadStatusModel.C_TASK] for row in self)
if task.status == task.QUEUED)
def set_downloading(self, task):
with self.set_downloading_access:
if task.status is task.DOWNLOADING:

View File

@ -170,6 +170,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
# When the amount of maximum downloads changes, notify the queue manager
changed_cb = lambda spinbutton: self.download_queue_manager.update_max_downloads()
self.spinMaxDownloads.connect('value-changed', changed_cb)
self.cbMaxDownloads.connect('toggled', changed_cb)
# Keep a reference to the last add podcast dialog instance
self._add_podcast_dialog = None