Browse Source

Add workers_number option

doc-issue-template
MrS0m30n3 10 years ago
parent
commit
0f63f956bf
2 changed files with 16 additions and 9 deletions
  1. 8
      youtube_dl_gui/downloadmanager.py
  2. 17
      youtube_dl_gui/optionsmanager.py

8
youtube_dl_gui/downloadmanager.py

@ -42,7 +42,6 @@ class DownloadManager(Thread):
"""Manages the download process.
Attributes:
WORKERS_NUMBER (int): Size of custom thread pool.
WAIT_TIME (float): Time in seconds to sleep.
Args:
@ -58,7 +57,6 @@ class DownloadManager(Thread):
"""
WORKERS_NUMBER = 3
WAIT_TIME = 0.1
def __init__(self, urls_list, opt_manager, log_manager=None):
@ -71,7 +69,7 @@ class DownloadManager(Thread):
self._successful = 0
self._running = True
self._workers = self._init_workers()
self._workers = self._init_workers(opt_manager.options['workers_number'])
self.start()
@property
@ -192,7 +190,7 @@ class DownloadManager(Thread):
path = os.path.join(path, YOUTUBEDL_BIN)
return path
def _init_workers(self):
def _init_workers(self, workers_number):
"""Initialize the custom thread pool.
Returns:
@ -200,7 +198,7 @@ class DownloadManager(Thread):
"""
youtubedl = self._youtubedl_path()
return [Worker(self.opt_manager, youtubedl, self.increase_succ, self.log_manager) for i in xrange(self.WORKERS_NUMBER)]
return [Worker(self.opt_manager, youtubedl, self.increase_succ, self.log_manager) for i in xrange(workers_number)]
class Worker(Thread):

17
youtube_dl_gui/optionsmanager.py

@ -175,6 +175,9 @@ class OptionsManager(object):
the LogManager. See main() function under __init__().
log_time (boolean): See logmanager.LogManager add_time attribute.
workers_number (int): Number of download workers that download manager
will spawn. Must be greater than zero.
"""
self.options = {
@ -217,7 +220,8 @@ class OptionsManager(object):
'youtubedl_path': self.config_path,
'cmd_args': '',
'enable_log': True,
'log_time': False
'log_time': False,
'workers_number': 3
}
def load_from_file(self):
@ -228,12 +232,12 @@ class OptionsManager(object):
with open(self.settings_file, 'rb') as settings_file:
try:
options = json.load(settings_file)
if self._settings_are_valid(options):
self.options = options
except:
self.load_default()
if self._settings_are_valid(options):
self.options = options
def save_to_file(self):
"""Save options to settings file. """
check_path(self.config_path)
@ -290,6 +294,11 @@ class OptionsManager(object):
for key, valid_list in rules_dict.items():
if settings_dictionary[key] not in valid_list:
return False
settings_dictionary['workers_number'] = int(settings_dictionary['workers_number'])
if settings_dictionary['workers_number'] < 1:
return False
return True

Loading…
Cancel
Save