Skip to content

Commit

Permalink
Add max_threads
Browse files Browse the repository at this point in the history
Signed-off-by: Luigi311 <[email protected]>
  • Loading branch information
luigi311 committed Sep 28, 2023
1 parent fb657d4 commit 3a0e60c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
5 changes: 2 additions & 3 deletions src/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3a0e60c

Please sign in to comment.