Skip to content

Using BackgroundTasks blocks StreamingResponse? #11022

Closed Answered by binbjz
rohan-mehta asked this question in Questions
Discussion options

You must be logged in to vote

Version info

# Name                    Version                  Build      Channel
python                    3.11.7                   hb885b13_0
fastapi                   0.109.0                  pypi_0      pypi
pydantic                  2.5.3                    pypi_0      pypi
pydantic-core             2.14.6                   pypi_0      pypi

ProductName:		macOS
ProductVersion:		14.2.1
BuildVersion:		23C71

Please try the following code snippet.

import time
import asyncio
import logging
from fastapi import FastAPI, BackgroundTasks
from fastapi.responses import StreamingResponse

app = FastAPI()

logging.basicConfig(level=logging.INFO)


async def stream_data():
    for i in range(10):…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rohan-mehta
Comment options

Answer selected by rohan-mehta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants