-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async behavior will turn to blocking behavior while working with GzipMiddleWare #84
Comments
demo # main.py
app = FastAPI()
from sse import route as subapp
app.mount("/sse", subapp)
app1 = FastAPI()
app1.add_middleware(GZipMiddleware, minimum_size=1000)
app1.include_router(be.route, prefix="/be")
app.mount("/", app1) # sse.py
from fastapi import APIRouter, Request, FastAPI
import asyncio
from sse_starlette.sse import EventSourceResponse
route = FastAPI()
@route.get("/s1")
async def message_stream(req: Request):
async def event_publisher():
i = 50
try:
while i:
i -= 1
# print(i)
yield dict(data=i)
await asyncio.sleep(0.5)
except asyncio.CancelledError as e:
print(f"Disconnected from client (via refresh/close) {req.client}")
# Do any other cleanup, if any
raise e
return EventSourceResponse(event_publisher()) |
@doglex, I am not sure whether I understand what you are trying to point out. README states: Caveat: SSE streaming does not work in combination with encode/starlette#20 (comment). Do you propose a solution/workaround for this? |
Yes, it is the issue |
If you have got a solution please open a PR. Would be much appreciated |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Workaround is sub application
The text was updated successfully, but these errors were encountered: