{Core} Pre-warm shared Azure SDK imports to avoid Python 3.14 importl…#33412
Closed
YangAn-microsoft wants to merge 1 commit into
Closed
{Core} Pre-warm shared Azure SDK imports to avoid Python 3.14 importl…#33412YangAn-microsoft wants to merge 1 commit into
YangAn-microsoft wants to merge 1 commit into
Conversation
️✔️AzureCLI-FullTest
|
|
Hi @YangAn-microsoft, |
️✔️AzureCLI-BreakingChangeTest
|
Collaborator
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CPython 3.14 changed
importlibso that when a thread tries to acquire a module lock that another thread already holds for the same module, it raises_DeadlockErrorinstead of blocking (CPython issue python/cpython#99953).Azure CLI's parallel command-module loader in
azure-cli-core(_load_modulesinazure/cli/core/__init__.py) uses a 4-threadThreadPoolExecutor. Each worker thread loads a command module that independently imports shared Azure SDK trunks (azure.core,azure.mgmt.core,msrest,msrestazure, ...). On Python 3.14 this races and surfaces as cascading_DeadlockError→KeyErrorfailures atazstartup.Local repro on Windows env314:
az --debugshows_DeadlockErrorfor e.g.cdnandmsrest.http_logger, with several modules failing to load.Fix
Add
_prewarm_shared_imports()at module scope inazure/cli/core/__init__.pyand call it from_load_modulesbefore the thread pool starts. It imports the shared SDK trunks once on the main thread so worker threads see fully-initialized entries insys.modulesand never contend on the module lock._REQUIRED_PREWARM_MODULES(hard deps ofazure-cli-core;ModuleNotFoundErrorpropagates) and_OPTIONAL_PREWARM_MODULES(transitive SDK packages;ModuleNotFoundErroron the optional name itself is suppressed, unrelatedModuleNotFoundErrorfrom inside an installed module still propagates)._prewarm_doneflag.Includes unit tests in
src/azure-cli-core/azure/cli/core/tests/test_prewarm_shared_imports.pycovering: all modules imported on first call, idempotency, suppressed optionalModuleNotFoundError, propagated requiredModuleNotFoundError, and propagated unrelatedModuleNotFoundErrorraised from inside an optional module.Notes
Testing Guide
python -m pytest src/azure-cli-core/azure/cli/core/tests/test_prewarm_shared_imports.pyaz --debugshows no_DeadlockError; all command modules load.