Skip to content

Commit 6fab8b3

Browse files
committed
fix: intermittent _DeadlockError
1 parent fec1915 commit 6fab8b3

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎src/azure-cli-core/azure/cli/core/aaz/_poller.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ def __init__(self, polling_generator, result_callback):
6262
self._done = None
6363
self._exception = None
6464

65+
# MSAL lazily imports requests when the credential is created on the polling thread,
66+
# which can raise _DeadlockError (seen on Python 3.14). Import it here on the main thread first.
67+
import requests # pylint: disable=unused-import
68+
6569
self._done = threading.Event()
6670
self._thread = threading.Thread(
6771
target=with_current_context(self._start),
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
import sys
6+
import unittest
7+
from unittest import mock
8+
9+
from azure.cli.core.aaz._poller import AAZLROPoller
10+
11+
12+
class TestAAZLROPoller(unittest.TestCase):
13+
14+
def test_requests_imported_before_polling_thread(self):
15+
loaded = []
16+
17+
def polling_generator():
18+
loaded.append("requests" in sys.modules)
19+
yield from ()
20+
21+
with mock.patch.dict(sys.modules):
22+
for name in [n for n in sys.modules if n == "requests" or n.startswith("requests.")]:
23+
del sys.modules[name]
24+
AAZLROPoller(polling_generator=polling_generator(), result_callback=None).wait()
25+
26+
self.assertEqual(loaded, [True])
27+
28+
29+
if __name__ == "__main__":
30+
unittest.main()

0 commit comments

Comments
 (0)