Skip to content

Commit f320960

Browse files
refactor: use constants for magic numbers
1 parent a53f78a commit f320960

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/azure-cli-core/azure/cli/core/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
ALWAYS_LOADED_MODULES = []
3535
# Extensions that will always be loaded if installed. They don't expose commands but hook into CLI core.
3636
ALWAYS_LOADED_EXTENSIONS = ['azext_ai_examples', 'azext_next']
37+
MODULE_LOAD_TIMEOUT_SECONDS = 30
38+
MAX_WORKER_THREAD_COUNT = 4
3739

3840

3941
def _configure_knack():
@@ -548,18 +550,18 @@ def _load_modules(self, args, command_modules):
548550
import concurrent.futures
549551

550552
results = []
551-
with ThreadPoolExecutor(max_workers=4) as executor:
553+
with ThreadPoolExecutor(max_workers=MAX_WORKER_THREAD_COUNT) as executor:
552554
future_to_module = {executor.submit(self._load_single_module, mod, args): mod
553555
for mod in command_modules if mod not in BLOCKED_MODS}
554556

555-
for future in concurrent.futures.as_completed(future_to_module, timeout=60):
557+
for future in future_to_module:
556558
try:
557-
# @NOTE: Timeout to counteract deadlocks, but how to test?
558-
result = future.result(timeout=30)
559+
result = future.result(timeout=MODULE_LOAD_TIMEOUT_SECONDS)
559560
results.append(result)
560561
except concurrent.futures.TimeoutError:
561562
mod = future_to_module[future]
562-
logger.warning("Module '%s' load timeout", mod)
563+
logger.warning("Module '%s' load timeout after %s seconds", mod, MODULE_LOAD_TIMEOUT_SECONDS)
564+
future.cancel()
563565
results.append(ModuleLoadResult(mod, {}, {}, 0,
564566
Exception(f"Module '{mod}' load timeout")))
565567
except Exception as ex:

0 commit comments

Comments
 (0)