Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/azure-cli-core/azure/cli/core/aaz/_poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def __init__(self, polling_generator, result_callback):
self._done = None
self._exception = None

# MSAL lazily imports requests when the credential is created on the polling thread,
# which can raise _DeadlockError (seen on Python 3.14). Import it here on the main thread first.
import requests # pylint: disable=unused-import

self._done = threading.Event()
self._thread = threading.Thread(
target=with_current_context(self._start),
Expand Down
30 changes: 30 additions & 0 deletions src/azure-cli-core/azure/cli/core/tests/test_aaz_poller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import sys
import unittest
from unittest import mock

from azure.cli.core.aaz._poller import AAZLROPoller


class TestAAZLROPoller(unittest.TestCase):

def test_requests_imported_before_polling_thread(self):
loaded = []

def polling_generator():
loaded.append("requests" in sys.modules)
yield from ()

with mock.patch.dict(sys.modules):
for name in [n for n in sys.modules if n == "requests" or n.startswith("requests.")]:
del sys.modules[name]
AAZLROPoller(polling_generator=polling_generator(), result_callback=None).wait()

self.assertEqual(loaded, [True])
Comment on lines +14 to +26


if __name__ == "__main__":
unittest.main()
Loading