Skip to content

Commit

Permalink
DownloadManager uses config for number of game download workers
Browse files Browse the repository at this point in the history
  • Loading branch information
GB609 authored Mar 7, 2025
1 parent 49d9299 commit de31ac7
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions minigalaxy/download_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ def __init__(self, session: Session, config: Config):

# The queues and associated limits
self.queues = [(self.__ui_queue, UI_DOWNLOAD_THREADS),
(self.__game_queue, GAME_DOWNLOAD_THREADS)]
(self.__game_queue, config.max_parallel_game_downloads)]

self.__cancel = {}
self.workers = []
self.workers = {}
# The list of currently active downloads
# These are items not in the queue, but currently being downloaded
self.active_downloads = {}
Expand All @@ -129,12 +129,16 @@ def __init__(self, session: Session, config: Config):

self.logger = logging.getLogger("minigalaxy.download_manager.DownloadManager")

for q, number_threads in self.queues:
for i in range(number_threads):
download_thread = threading.Thread(target=lambda: self.__download_thread(q))
download_thread.daemon = True
download_thread.start()
self.workers.append(download_thread)
for q, number_threads in self.queues
self.workers[q] = []
self.__initialize_workers(q, number_threads)

def __initialize_workers(self, queue, num_workers):
for i in range(num_workers):
download_thread = threading.Thread(target=lambda: self.__download_thread(queue))
download_thread.daemon = True
download_thread.start()
self.workers[queue].append(download_thread)

def add_active_downloads_listener(self, listener):
if listener not in self.download_list_change_listener:
Expand Down

0 comments on commit de31ac7

Please sign in to comment.