Draft
[Core] Fix #33996: Eagerly import requests and msal in identity.py to prevent Python 3.14 import-lock deadlock#9
requests and msal in identity.py to prevent Python 3.14 import-lock deadlock#9Conversation
Co-authored-by: a0x1ab <59631311+a0x1ab@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement changes from automated review feedback
[Core] Fix #33996: Eagerly import Aug 27, 2026
requests and msal in identity.py to prevent Python 3.14 import-lock deadlock
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.
Python 3.14 raises
_DeadlockErrorwhen background threads race to lazily import modules whose import-lock ordering creates a cycle (e.g.requests.structures). Pre-loadingrequestsandmsalon the main thread inidentity.pyeliminates the race.Related command
az login(and any command that triggers authentication viaazure.cli.core.auth.identity)Description
auth/identity.py: Add eager top-level imports ofrequestsandmsalwith# pylint: disable=unused-import, accompanied by a comment explaining the Python 3.14 deadlock rationale.tests/test_auth_eager_import.py: New regression test that evicts the relevant modules fromsys.modules, re-importsazure.cli.core.auth.identity, and asserts thatrequests,requests.structures, andmsalare all present insys.modulesafterward — guarding against the eager imports being silently dropped in the future.Testing Guide
History Notes
{Core} Fix Python 3.14
_DeadlockErrorcaused by lazy import ofrequests/msalin background threadsThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.