From 3a0e60c772006e4aa1351907848d3e3bf906694b Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Thu, 28 Sep 2023 10:00:07 -0600 Subject: [PATCH] Add max_threads Signed-off-by: Luigi311 --- .env.sample | 6 ++++++ src/functions.py | 5 ++--- src/plex.py | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.env.sample b/.env.sample index 2f231ea..2953a0e 100644 --- a/.env.sample +++ b/.env.sample @@ -18,6 +18,12 @@ SLEEP_DURATION = "3600" ## Log file where all output will be written to LOGFILE = "log.log" +## Timeout for requests for jellyfin +REQUEST_TIMEOUT = 300 + +## Max threads for processing +MAX_THREADS = 32 + ## Map usernames between servers in the event that they are different, order does not matter ## Comma separated for multiple options #USER_MAPPING = { "testuser2": "testuser3", "testuser1":"testuser4" } diff --git a/src/functions.py b/src/functions.py index 2e7529b..49dc67e 100644 --- a/src/functions.py +++ b/src/functions.py @@ -63,12 +63,11 @@ def search_mapping(dictionary: dict, key_value: str): return None -def future_thread_executor(args: list, workers: int = -1): +def future_thread_executor(args: list, threads: int = 32): futures_list = [] results = [] - if workers == -1: - workers = min(32, os.cpu_count() * 2) + workers = min(int(os.getenv("MAX_THREADS", 32)), os.cpu_count() * 2, threads) with ThreadPoolExecutor(max_workers=workers) as executor: for arg in args: diff --git a/src/plex.py b/src/plex.py index 0bcdf7b..715daae 100644 --- a/src/plex.py +++ b/src/plex.py @@ -174,7 +174,7 @@ def get_user_library_watched(user, user_plex, library): args.append([get_user_library_watched_show, show]) for show_guids, episode_guids in future_thread_executor( - args, workers=min(os.cpu_count(), 4) + args, threads=4 ): if show_guids and episode_guids: # append show, season, episode