mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-28 14:04:49 -04:00
Repace threading with ThreadPoolExecutor
This commit is contained in:
parent
e28e8b31ea
commit
d2b21ca937
1 changed files with 10 additions and 15 deletions
|
@ -7,7 +7,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import concurrent.futures
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from tempfile import gettempdir
|
from tempfile import gettempdir
|
||||||
from typing import Any, Generator, Iterable, Union
|
from typing import Any, Generator, Iterable, Union
|
||||||
|
@ -622,20 +622,15 @@ class Tracklist(list):
|
||||||
target = self._download_item
|
target = self._download_item
|
||||||
|
|
||||||
if kwargs.get("concurrent_downloads", True):
|
if kwargs.get("concurrent_downloads", True):
|
||||||
processes = []
|
# Tidal errors out with unlimited concurrency
|
||||||
for item in self:
|
max_workers = 15 if self.client.source == 'tidal' else None
|
||||||
proc = threading.Thread(
|
with concurrent.futures.ThreadPoolExecutor(max_workers) as executor:
|
||||||
target=target, args=(item,), kwargs=kwargs, daemon=True
|
futures = [executor.submit(target, item, **kwargs) for item in self]
|
||||||
)
|
try:
|
||||||
proc.start()
|
concurrent.futures.wait(futures)
|
||||||
processes.append(proc)
|
except (KeyboardInterrupt, SystemExit):
|
||||||
|
executor.shutdown()
|
||||||
try:
|
exit("Aborted!")
|
||||||
for proc in processes:
|
|
||||||
proc.join()
|
|
||||||
except (KeyboardInterrupt, SystemExit):
|
|
||||||
click.echo("Aborted!")
|
|
||||||
exit()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for item in self:
|
for item in self:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue