diff --git a/fastanime/AnimeProvider.py b/fastanime/AnimeProvider.py index 25fb901..a307a24 100644 --- a/fastanime/AnimeProvider.py +++ b/fastanime/AnimeProvider.py @@ -1,7 +1,4 @@ -"""An abstraction over all providers offering added features with a simple and well typed api - -[TODO:description] -""" +"""An abstraction over all providers offering added features with a simple and well typed api""" import importlib import logging @@ -40,6 +37,10 @@ class AnimeProvider: def lazyload_provider(self, provider): """updates the current provider being used""" + try: + self.anime_provider.session.kill_connection_to_db() + except Exception: + pass _, anime_provider_cls_name = anime_sources[provider].split(".", 1) package = f"fastanime.libs.anime_provider.{provider}" provider_api = importlib.import_module(".api", package) diff --git a/fastanime/libs/common/requests_cacher.py b/fastanime/libs/common/requests_cacher.py index ff7f1e0..6183e72 100644 --- a/fastanime/libs/common/requests_cacher.py +++ b/fastanime/libs/common/requests_cacher.py @@ -60,6 +60,7 @@ class CachedRequestsSession(requests.Session): ): super().__init__(*args, **kwargs) + self.lockfile_path = cache_db_lock_file self.cache_db_path = cache_db_path self.max_lifetime = max_lifetime self.max_size = max_size @@ -201,6 +202,11 @@ class CachedRequestsSession(requests.Session): content in caching_mimetypes[mime] for content in contents.split("+") ) + def kill_connection_to_db(self): + lockfile_path = pathlib.Path(self.lockfile_path) + self.connection.close() + lockfile_path.unlink(missing_ok=True) + @staticmethod def acquirer_lock(lock_file: str): """the function creates a lock file preventing other instances of the cacher from running at the same time"""