From 6a2e2e0f5a3ec7991f876a27067f9a2b0497ce39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Thu, 7 Nov 2019 23:11:41 -0500 Subject: [PATCH] Empty cache when ValueError is raised with 'unsupported pickle protocol: 3'. This happen when cache have been pickled with Python3 but is read by Python2. --- bazarr/get_providers.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/bazarr/get_providers.py b/bazarr/get_providers.py index 316dcaf8b..e792424af 100644 --- a/bazarr/get_providers.py +++ b/bazarr/get_providers.py @@ -10,6 +10,7 @@ from get_args import args from config import settings from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError from subliminal.exceptions import DownloadLimitExceeded, ServiceUnavailable +from subliminal import region as subliminal_cache_region VALID_THROTTLE_EXCEPTIONS = (TooManyRequests, DownloadLimitExceeded, ServiceUnavailable, APIThrottled, ParseResponseError) @@ -154,13 +155,20 @@ def provider_throttle(name, exception): throttle_until = datetime.datetime.now() + throttle_delta if cls_name not in VALID_COUNT_EXCEPTIONS or throttled_count(name): - tp[name] = (cls_name, throttle_until, throttle_description) - settings.general.throtteled_providers = str(tp) - with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle: - settings.write(handle) - - logging.info("Throttling %s for %s, until %s, because of: %s. Exception info: %r", name, throttle_description, - throttle_until.strftime("%y/%m/%d %H:%M"), cls_name, exception.message) + if cls_name == 'ValueError' and exception.message.startswith('unsupported pickle protocol'): + for fn in subliminal_cache_region.backend.all_filenames: + try: + os.remove(fn) + except (IOError, OSError): + logging.debug("Couldn't remove cache file: %s", os.path.basename(fn)) + else: + tp[name] = (cls_name, throttle_until, throttle_description) + settings.general.throtteled_providers = str(tp) + with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle: + settings.write(handle) + + logging.info("Throttling %s for %s, until %s, because of: %s. Exception info: %r", name, throttle_description, + throttle_until.strftime("%y/%m/%d %H:%M"), cls_name, exception.message) def throttled_count(name):