mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-27 09:58:10 +01:00
Fixed for max parallel download
Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
parent
0a9c900bb4
commit
6fc01d225e
2 changed files with 10 additions and 8 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
- Fixed:
|
- Fixed:
|
||||||
* Fixed to create custom repositories (Thanks to mac-a-r0ni)
|
* Fixed to create custom repositories (Thanks to mac-a-r0ni)
|
||||||
|
* Fixed OSError: [Errno 24] too many open files for parallel download (Thanks to rizitis)
|
||||||
|
|
||||||
### 5.1.0 - 06/06/2024
|
### 5.1.0 - 06/06/2024
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import threading
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from multiprocessing import Process, Semaphore
|
from multiprocessing import Process
|
||||||
from urllib.parse import unquote, urlparse
|
from urllib.parse import unquote, urlparse
|
||||||
|
|
||||||
from slpkg.configs import Configs
|
from slpkg.configs import Configs
|
||||||
|
@ -35,7 +36,8 @@ class Downloader(Configs): # pylint: disable=[R0902]
|
||||||
'lftp': self.set_lftp_downloader
|
'lftp': self.set_lftp_downloader
|
||||||
}
|
}
|
||||||
|
|
||||||
self.semaphore = Semaphore(self.maximum_parallel)
|
# Semaphore to control the number of concurrent threads
|
||||||
|
self.semaphore = threading.BoundedSemaphore(int(self.maximum_parallel))
|
||||||
|
|
||||||
self.option_for_parallel: bool = self.utils.is_option(
|
self.option_for_parallel: bool = self.utils.is_option(
|
||||||
('-P', '--parallel'), flags)
|
('-P', '--parallel'), flags)
|
||||||
|
@ -51,6 +53,7 @@ class Downloader(Configs): # pylint: disable=[R0902]
|
||||||
"""Download sources with parallel mode."""
|
"""Download sources with parallel mode."""
|
||||||
processes: list = []
|
processes: list = []
|
||||||
for urls, path in sources.values():
|
for urls, path in sources.values():
|
||||||
|
with self.semaphore:
|
||||||
for url in urls:
|
for url in urls:
|
||||||
proc = Process(target=self.tools, args=(url, path))
|
proc = Process(target=self.tools, args=(url, path))
|
||||||
processes.append(proc)
|
processes.append(proc)
|
||||||
|
@ -72,7 +75,6 @@ class Downloader(Configs): # pylint: disable=[R0902]
|
||||||
url (str): The URL link.
|
url (str): The URL link.
|
||||||
path (Path): Path to save.
|
path (Path): Path to save.
|
||||||
"""
|
"""
|
||||||
self.semaphore.acquire()
|
|
||||||
url_parse: str = urlparse(url).path
|
url_parse: str = urlparse(url).path
|
||||||
self.filename: str = unquote(Path(url_parse).name)
|
self.filename: str = unquote(Path(url_parse).name)
|
||||||
|
|
||||||
|
@ -83,7 +85,6 @@ class Downloader(Configs): # pylint: disable=[R0902]
|
||||||
|
|
||||||
self.multi_process.process(self.downloader_command)
|
self.multi_process.process(self.downloader_command)
|
||||||
self.check_if_downloaded(url, path)
|
self.check_if_downloaded(url, path)
|
||||||
self.semaphore.release()
|
|
||||||
|
|
||||||
def set_wget_downloader(self, url: str, path: Path) -> None:
|
def set_wget_downloader(self, url: str, path: Path) -> None:
|
||||||
"""Set for wget tool.
|
"""Set for wget tool.
|
||||||
|
|
Loading…
Reference in a new issue