File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -205,9 +205,19 @@ class _TokenState(Enum):
205205class Refreshable (TokenSource ):
206206 """A token source that supports refreshing expired tokens."""
207207
208- _EXECUTOR = ThreadPoolExecutor (max_workers = 10 )
208+ _EXECUTOR = None
209+ _EXECUTOR_LOCK = threading .Lock ()
209210 _DEFAULT_STALE_DURATION = timedelta (minutes = 3 )
210211
212+ @classmethod
213+ def _get_executor (cls ):
214+ """Lazy initialization of the ThreadPoolExecutor."""
215+ if cls ._EXECUTOR is None :
216+ with cls ._EXECUTOR_LOCK :
217+ if cls ._EXECUTOR is None :
218+ cls ._EXECUTOR = ThreadPoolExecutor (max_workers = 10 )
219+ return cls ._EXECUTOR
220+
211221 def __init__ (self ,
212222 token : Token = None ,
213223 disable_async : bool = True ,
@@ -289,7 +299,7 @@ def _refresh_internal():
289299 with self ._lock :
290300 if not self ._is_refreshing and not self ._refresh_err :
291301 self ._is_refreshing = True
292- self . _EXECUTOR .submit (_refresh_internal )
302+ Refreshable . _get_executor () .submit (_refresh_internal )
293303
294304 @abstractmethod
295305 def refresh (self ) -> Token :
You can’t perform that action at this time.
0 commit comments