From e47a2863e8dcc245dac02026220237c59c55d2cd Mon Sep 17 00:00:00 2001 From: RemixDev Date: Thu, 11 Feb 2021 17:30:53 +0100 Subject: [PATCH] Removed eventlet --- deemix/app/downloadjob.py | 21 +++++++++++---------- deemix/app/queuemanager.py | 3 +-- deemix/app/spotifyhelper.py | 5 +---- deemix/types/Track.py | 6 +++--- requirements.txt | 1 - setup.py | 2 +- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/deemix/app/downloadjob.py b/deemix/app/downloadjob.py index f0e08b4..d436422 100644 --- a/deemix/app/downloadjob.py +++ b/deemix/app/downloadjob.py @@ -1,9 +1,10 @@ -import eventlet -from eventlet.green.subprocess import call as execute -requests = eventlet.import_patched('requests') +import requests get = requests.get request_exception = requests.exceptions +from concurrent.futures import ThreadPoolExecutor +from time import sleep + from os.path import sep as pathSep from pathlib import Path from shlex import quote @@ -74,12 +75,12 @@ def downloadImage(url, path, overwrite=OverwriteOption.DONT_OVERWRITE): pictureSize = int(pictureUrl[:pictureUrl.find("x")]) if pictureSize > 1200: logger.warn("Couldn't download "+str(pictureSize)+"x"+str(pictureSize)+" image, falling back to 1200x1200") - eventlet.sleep(1) + sleep(1) return downloadImage(urlBase+pictureUrl.replace(str(pictureSize)+"x"+str(pictureSize), '1200x1200'), path, overwrite) logger.error("Image not found: "+url) except (request_exception.ConnectionError, request_exception.ChunkedEncodingError, u3SSLError) as e: logger.error("Couldn't download Image, retrying in 5 seconds...: "+url+"\n") - eventlet.sleep(5) + sleep(5) return downloadImage(url, path, overwrite) except OSError as e: if e.errno == errno.ENOSPC: @@ -114,9 +115,9 @@ class DownloadJob: if result: self.singleAfterDownload(result) elif isinstance(self.queueItem, QICollection): tracks = [None] * len(self.queueItem.collection) - pool = eventlet.GreenPool(size=self.settings['queueConcurrency']) - for pos, track in enumerate(self.queueItem.collection, start=0): - tracks[pos] = pool.spawn(self.downloadWrapper, track) + with ThreadPoolExecutor(self.settings['queueConcurrency']) as executor: + for pos, track in enumerate(self.queueItem.collection, start=0): + tracks[pos] = executor.submit(self.downloadWrapper, track) pool.waitall() self.collectionAfterDownload(tracks) if self.interface: @@ -525,7 +526,7 @@ class DownloadJob: except (request_exception.ConnectionError, request_exception.ChunkedEncodingError) as e: if writepath.is_file(): writepath.unlink() logger.warn(f"[{track.mainArtist.name} - {track.title}] Error while downloading the track, trying again in 5s...") - eventlet.sleep(5) + sleep(5) return downloadMusic(track, trackAPI_gw) except OSError as e: if e.errno == errno.ENOSPC: @@ -680,7 +681,7 @@ class DownloadJob: logger.info(f'{itemName} retrying from byte {chunkLength}') return self.streamTrack(stream, track, chunkLength) except (request_exception.ConnectionError, requests.exceptions.ReadTimeout): - eventlet.sleep(2) + sleep(2) return self.streamTrack(stream, track, start) def updatePercentage(self): diff --git a/deemix/app/queuemanager.py b/deemix/app/queuemanager.py index 4547bf8..0305945 100644 --- a/deemix/app/queuemanager.py +++ b/deemix/app/queuemanager.py @@ -9,9 +9,8 @@ import logging from pathlib import Path import json from os import remove -import eventlet import uuid -urlopen = eventlet.import_patched('urllib.request').urlopen +from urllib.request import urlopen logging.basicConfig(level=logging.INFO) logger = logging.getLogger('deemix') diff --git a/deemix/app/spotifyhelper.py b/deemix/app/spotifyhelper.py index 0eaf907..d60e819 100644 --- a/deemix/app/spotifyhelper.py +++ b/deemix/app/spotifyhelper.py @@ -1,10 +1,7 @@ -import eventlet import json from pathlib import Path -eventlet.import_patched('requests.adapters') - -spotipy = eventlet.import_patched('spotipy') +import spotipy SpotifyClientCredentials = spotipy.oauth2.SpotifyClientCredentials from deemix.utils.localpaths import getConfigFolder from deemix.app.queueitem import QIConvertable diff --git a/deemix/types/Track.py b/deemix/types/Track.py index 523384f..a354772 100644 --- a/deemix/types/Track.py +++ b/deemix/types/Track.py @@ -1,5 +1,5 @@ -import eventlet -requests = eventlet.import_patched('requests') +from time import sleep +import requests import logging logging.basicConfig(level=logging.INFO) @@ -83,7 +83,7 @@ class Track: ) result_json = site.json() except: - eventlet.sleep(2) + sleep(2) return self.retriveFilesizes(dz) if len(result_json['error']): raise APIError(json.dumps(result_json['error'])) diff --git a/requirements.txt b/requirements.txt index 3242ce0..6f5ae55 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,4 @@ pycryptodomex mutagen requests spotipy>=2.11.0 -eventlet deezer-py diff --git a/setup.py b/setup.py index f14b4e9..ec9d9b6 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ setup( python_requires='>=3.6', packages=find_packages(exclude=("tests",)), include_package_data=True, - install_requires=["click", "pycryptodomex", "mutagen", "requests", "spotipy>=2.11.0", "eventlet", "deezer-py"], + install_requires=["click", "pycryptodomex", "mutagen", "requests", "spotipy>=2.11.0", "deezer-py"], entry_points={ "console_scripts": [ "deemix=deemix.__main__:download",