Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix StreamingResponse docs: warn about blocking operations in async generators#14991

Closed
thakoreh wants to merge 1 commit into
fastapi:masterfrom
thakoreh:fix-streamingresponse-docs
Closed

Fix StreamingResponse docs: warn about blocking operations in async generators#14991
thakoreh wants to merge 1 commit into
fastapi:masterfrom
thakoreh:fix-streamingresponse-docs

Conversation

@thakoreh

Copy link
Copy Markdown

Description

Fixes issue #14680 - StreamingResponse doc example needs correction

Problem

The documentation states that StreamingResponse "Takes an async generator or a normal generator/iterator" but doesn't explain that async generators need to actually await something to work properly.

Users might use in an async generator, which blocks the event loop and prevents proper streaming.

Solution

Added a warning admonition explaining that:

  • Async generators should use instead of
  • Blocking operations prevent proper streaming

Changes

  • Added warning in docs/en/docs/advanced/custom-response.md

…ngResponse

Async generators need to use asyncio.sleep() instead of time.sleep() to
avoid blocking the event loop and prevent proper streaming.

Fixes: fastapi#14680
@github-actions github-actions Bot added the docs Documentation about how to use FastAPI label Feb 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@YuriiMotov

Copy link
Copy Markdown
Member

Thanks for your interest, but this doesn't really resolve the issue #14680.

There is already another PR that will resolve that issue: #14681

@YuriiMotov YuriiMotov closed this Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation about how to use FastAPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants