Skip to content

Commit

Permalink
Improved providers throttling and prevent hammering providers by upda…
Browse files Browse the repository at this point in the history
…ting throttled providers on each iteration of the loop.
  • Loading branch information
morpheus65535 committed Dec 18, 2021
1 parent 5d1dccd commit 5ff3fe4
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 160 deletions.
21 changes: 8 additions & 13 deletions bazarr/get_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import time
import socket
import requests
import ast

from get_args import args
from config import settings, get_array_from
Expand Down Expand Up @@ -328,9 +327,11 @@ def get_throttled_providers():
if os.path.exists(os.path.join(args.config_dir, 'config', 'throttled_providers.dat')):
with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'throttled_providers.dat')), 'r') as \
handle:
providers = ast.literal_eval(handle.read())
except (OSError, ValueError):
providers = {}
providers = eval(handle.read())
except:
# set empty content in throttled_providers.dat
logging.error("Invalid content in throttled_providers.dat. Resetting")
set_throttled_providers(providers)
finally:
return providers

Expand All @@ -340,12 +341,6 @@ def set_throttled_providers(data):
handle.write(data)


try:
tp = get_throttled_providers()
if not isinstance(tp, dict):
raise ValueError('tp should be a dict')
except Exception:
logging.error("Invalid content in throttled_providers.dat. Resetting")
# set empty content in throttled_providers.dat
set_throttled_providers('')
tp = get_throttled_providers()
tp = get_throttled_providers()
if not isinstance(tp, dict):
raise ValueError('tp should be a dict')

0 comments on commit 5ff3fe4

Please sign in to comment.