Closed controZheng closed 1 year ago
I am not sure whether I do understand your question, I am afraid. But it does not sound like an sse-starlette issue. If so please re-open with a concrete example where sse-starlette does not behave as expected.
sse-starlette
How does sse-startlet know if the request has been cancelled ?
@controZheng an asyncio.CancelledError
is raised.
try:
while True:
async for event in generator(db, params):
yield {
"event": event.event,
"data": event.model_dump_json(),
}
yield {"event": "stop", "data": {}}
break
except asyncio.CancelledError as e:
logger.info(f"Disconnected from client (via refresh/close) {request.client}")
raise e
except HTTPException as e:
logger.info(f"Disconnected from client (via HTTPException) {request.client}")
yield {"event": "error", "data": json.dumps({"detail": e.detail})}
I have a fastAPI stream request, and when I call it on the client, I can interrupt the request. So how do I know the action of this interrupt on the fastAPI server?