From 86d6c211af8ac0b81e05937fea1973ec78bc9226 Mon Sep 17 00:00:00 2001 From: Vitiko Date: Thu, 31 Mar 2022 23:11:32 -0400 Subject: [PATCH] Fix ValueError for persistent pools on multithreaded setups --- libs/subliminal_patch/core.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/subliminal_patch/core.py b/libs/subliminal_patch/core.py index db98406c9..5e59ca895 100644 --- a/libs/subliminal_patch/core.py +++ b/libs/subliminal_patch/core.py @@ -548,9 +548,19 @@ def __init__(self, max_workers=None, *args, **kwargs): super(SZAsyncProviderPool, self).__init__(*args, **kwargs) #: Maximum number of threads to use - self.max_workers = max_workers or len(self.providers) + self._max_workers_set = max_workers is not None + self.max_workers = (max_workers or len(self.providers)) or 1 logger.info("Using %d threads for %d providers (%s)", self.max_workers, len(self.providers), self.providers) + def update(self, *args, **kwargs): + updated = super().update(*args, **kwargs) + + if (len(self.providers) and not self._max_workers_set) and len(self.providers) != self.max_workers: + logger.debug("This pool will use %d threads from now on", len(self.providers)) + self.max_workers = len(self.providers) + + return updated + def list_subtitles_provider(self, provider, video, languages): # list subtitles provider_subtitles = None