Azure / Azure/azure-sdk-for-python
DocumentIntelligenceClient.begin_analyze_document and poller.result() block event loop despite async API
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 3.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 193
Description
- **Package Name**: azure-ai-documentintelligence
- **Package Version**: 1.0.0 - 1.0.2
- **Operating System**: Windows 11, Linux (Azure Functions Python 4.x Docker base image)
- **Python Version**: Python 3.11
**Describe the bug**
The `begin_analyze_document` method of `DocumentIntelligenceClient` (from the async `azure.ai.documentintelligence.aio` package) and its returned poller’s `result()` method perform blocking I/O internally. Despite being part of the async SDK, these calls block the asyncio event loop, causing delays and concurrency issues in frameworks like FastAPI.
**To Reproduce**
Steps to reproduce the behavior:
1. Use DocumentIntelligenceClient from azure.ai.documentintelligence.aio in an async FastAPI endpoint.
2. Call await client.begin_analyze_document(...).
3. Await poller.result().
4. Observe that the FastAPI event loop is blocked during the call, causing other requests to stall.
**Expected behavior**
Both `begin_analyze_document` and `poller.result()` should perform non-blocking async I/O, allowing other asyncio tasks to run concurrently without delay.
**Screenshots**
N/A
**Additional context**
As a temporary workaround, offloading the blocking calls to a thread using asyncio.to_thread() avoids event loop blocking.
Contributor guide
Assessment
This issue has not been assessed yet.